I want to build a block diagonal matrix (A) from a known matrix (B) by only keeping the elements in the block diagonal from matrix (B). I would like to use R to do it.
For example, B is a 6 by 6 matrix.
B <- matrix(rnorm(36), nrow = 6)
I am looking for a function like this: function(B,3) (3 is just a random number, it represents the total numbers of the block) which returns matrix A like this:
[1,] B11 B12 . . . .
[2,] B21 B22 . . . .
[3,] . . B33 B34 . .
[4,] . . B43 B44 . .
[5,] . . . . B55 B56
[6,] . . . . B65 B66
Really appreciate any help