Does R have a base function to bind matrices in a block-diagonal shape?
The following does the job, but I'd like to know if there is a standard way:
a <- matrix(1:6, 2, 3)
b <- matrix(7:10, 2, 2)
rbind(cbind(a, matrix(0, nrow=nrow(a), ncol=ncol(b))),
cbind(matrix(0, nrow=nrow(b), ncol=ncol(a)), b))
# [,1] [,2] [,3] [,4] [,5]
#[1,] 1 3 5 0 0
#[2,] 2 4 6 0 0
#[3,] 0 0 0 7 9
#[4,] 0 0 0 8 10
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…