Create a Block Diagonal Matrix

Description

It creates a block diagonal matrix from a list of numeric or character matrices.

Usage

1

Arguments

x

A list of numeric or character matrices (or values)

Value

A numeric or character block diagonal matrix

Author(s)

Mike W.-L. Cheung <mikewlcheung@nus.edu.sg>

References

It was based on a function posted by Scott Chasalow at http://www.math.yorku.ca/Who/Faculty/Monette/pub/stmp/0827.html.

See Also

bdiagRep, matrix2bdiag

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Block diagonal matrix of numerics
bdiagMat( list(matrix(1:4,nrow=2,ncol=2),
               matrix(5:6,nrow=1,ncol=2)) )
#      [,1] [,2] [,3] [,4]
# [1,]    1    3    0    0
# [2,]    2    4    0    0
# [3,]    0    0    5    6

## Block diagonal matrix of characters
bdiagMat( list(matrix(letters[1:4],nrow=2,ncol=2),
               matrix(letters[5:6],nrow=1,ncol=2)) )
#      [,1] [,2] [,3] [,4]
# [1,] "a"  "c"  "0"  "0" 
# [2,] "b"  "d"  "0"  "0" 
# [3,] "0"  "0"  "e"  "f" 

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.