b.diag {BFI}R Documentation

Create a Block Diagonal Matrix

Description

Construct a block diagonal matrix using multiple given block matrices.

Usage

b.diag(..., fill = 0)

Arguments

...

individual matrices or one list of matrices.

fill

non-block-diagonal elements. Default is 0.

Details

Avoid combining matrices and lists for the ... argument.

b.diag() covers the arguments of type "character".

If a sparse matrix needed, run the following:

library(Matrix); Matrix(b_diag, sparse = TRUE)

where b_diag is the matrix returned by b.diag().

Value

b.diag() returns a block diagonal matrix obtained by combining the arguments.

Author(s)

Hassan Pazira
Maintainer: Hassan Pazira hassan.pazira@radboudumc.nl

Examples


b.diag(1, matrix(1:3, 3,4), diag(3:2))

b.diag(matrix(1:6, 2), as.character(2))

lists <- list(1, 2:3, diag(4:6), 7, cbind(8,9:12), 13:15)
b.diag(lists)
identical(b.diag(lists), b.diag(lapply(lists, as.matrix)))

b.diag(replicate(3, matrix(round(rnorm(9)), 3, 3), simplify=FALSE))


[Package BFI version 2.0.1 Index]