Suppose I have a list Z
consisting of many matrices and I want to construct a block diagonal matrix from it.
ex :
[[1]]
[,1] [,2] [,3]
[1,] 1.002500e+00 0.001930454 1.388794e-11
[2,] 1.930454e-03 1.002500000 1.930454e-03
[3,] 1.388794e-11 0.001930454 1.002500e+00
[[2]]
[,1] [,2] [,3]
[1,] 1.002500e+00 0.001930454 1.388794e-11
[2,] 1.930454e-03 1.002500000 1.930454e-03
[3,] 1.388794e-11 0.001930454 1.002500e+00
I want to create a block diagonal matrix , I am currently using
block = bdiag(z)
However the bdiag
command is slow when the number of matrices in the list is large. What is a fast and easy way to construct a block diagonal matrix from the list?
Note my matrix is also symmetric and every matrix in the list has similar dimensions.
l <- rep(list(matrix(1:625, 25)), 200); x <- Matrix::bdiag(l)
finishes almost instantly – rawrbdiag()
step is really the limiting factor ... ? – Ben Bolker