Build a block diagonal matrix.

blkdiag(...)

Arguments

...

sequence of non-empty, numeric matrices

Details

Generate a block diagonal matrix from A, B, C, .... All the arguments must be numeric and non-empty matrices.

Value

a numeric matrix

Note

Vectors as input have to be converted to matrices before. Note that as.matrix(v) with v a vector will generate a column vector; use matrix(v, nrow=1) if a row vector is intended.

See also

Examples

a1 <- matrix(c(1,2), 1)
a2 <- as.matrix(c(1,2))
blkdiag(a1, diag(1, 2, 2), a2)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    1    2    0    0    0
#> [2,]    0    0    1    0    0
#> [3,]    0    0    0    1    0
#> [4,]    0    0    0    0    1
#> [5,]    0    0    0    0    2