I have a basic matrix mat and I hope to get an R object x = (mat, mat, ...) where mat is repeated for 100 times. If this is possible, then I can pass x to a function which takes a vector of matrix names. I tried rep(mat, 100) but it seems that the matrix class is no longer maintained. Any suggestions? Thanks!
Update: Basically I plan to use
grp.ids <- as.factor(c(rep(1,8), rep(2,4), rep(3,2)))
x <- model.matrix(~grp.ids)
do.call(blockMatrixDiagonal,
replicate(100, x, simplify=FALSE))
where the blockMatrixDiagonal function can be found here. Then R gives an error: number of items to replace is not a multiple of replacement length. What I really hope to get via these coding is a block diagonal matrix. Thanks 🙂
Your input matrix is not appropriate for building a block diagonal matrix since it’s not a square matrix (i.e., the number of rows equals the number of columns).
Let me cite two resources on block diagonal matrices.
1) Wikipedia:
2) The description of the function
blockMatrixDiagonal:You can combine your non-square matrices with the function
adiagfrom the packagemagic. With your matrixx: