Dear R users,

I'd like to create a block diagonal matrix with each rows in a matrix.

Here is a simple example. (In fact, the matrix is big)


x <- matrix(1:20, 4,5)

> x
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    5    9   13   17
[2,]    2    6   10   14   18
[3,]    3    7   11   15   19
[4,]    4    8   12   16   20


With each rows in matrix x, I'd like to make the matrix below.


     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9][,10]
[,11][,12][,13][,14][,15][,16][,17][,18][,19][,20]
[1,]    1    5    9   13   17   0    0    0    0    0     0    0    0
0    0     0    0    0    0    0
[2,]    0    0    0    0    0    2    6   10   14   18   0    0    0
0    0     0    0    0    0    0
[3,]    0    0    0    0    0    0    0    0    0    0     3    7   11
15   19   0    0    0    0    0
[4,]    0    0    0    0    0    0    0    0    0    0     0    0    0
0    0     4    8   12   16   20


Any suggestion will be greatly appreciated.

Best,

Kathryn Lord

	[[alternative HTML version deleted]]

