[R] creating lists of random matrices

Evan Cooch evan.cooch at gmail.com
Wed Nov 9 19:32:54 CET 2016

So, its easy enough to create a random matrix, using something like (say)


which generates a (2x2) matrix with random N(0,1) in each cell.

But, what I need to be able to do is create a 'list' of such random 
matrices, where the length of the list (i.e., the number of said random 
matrices I store in the list) is some variable I can pass to the 
function (or loop).

I tried the obvious like

hold <- list()
for (i in 1:5) {
     hold[[i]] <- matrix(rnorm(4),2,2)

While this works, it seems inelegant, and I'm wondering if there is a 
better (more efficient) way to accomplish the same thing -- perhaps 
avoiding the loop.

Thanks in advance...

More information about the R-help mailing list