Dear R users, I'm trying to build a diagonal matrix from a group of
matrices. These matrices have been built in a for loop. That is, I've
subsetted a preliminar matrix to obtain a certain number of square
sub-matrices, and now I need to create a diagonal out of these.
Suppose my matrix is a square matrix 21x21, and that I want to diagonalize
616 submatrices of this one. To do this I do:

diag <- rep(1,21)
work.cov <- matrix(0,21,21)
diag(work.cov) <- diag
samp <- sample(seq(1:21),616,replace=T)
for (i in 1:length(samp)){
A <- work.cov[1:samp[i],1:samp[i]]
}

Now, I want to put these 616 square matrices on the diagonal of a new
matrix. The question is: how I can I do this? I know there's a function
bdiag that creates diagonal matrix with various elements (vectors and
matrices), but the problem here's that my matrices exists only in the loop,
not outside of it, and they all correspond to the same matrix V computed
under different values of i.
Thansk in advance
niccolò

	[[alternative HTML version deleted]]

