[R] storing matrix(variables) in loop

Márcio Resende mresendeufv at yahoo.com.br
Mon Mar 15 15:44:37 CET 2010

Hello R-helpers,
I have the following code that works well, 

b <-list()
for (i in 1:3){
a <- matrix(runif(1),3,3)
b[[i]] <- a

however, I need to do something similar with two loops and I was looking for
something that would look like

b <- list()
for (i in 1:3){
for (j in 1:4){
a <- matrix(runif(1),3,3)
b[[i,j]] <- a #but this doesn´t work

Anyway, I wanted "b" to loop like
[[i=1, j=1]]         [[i=1, j=2]]     (...)
a[i=1, j=1]           a[i=1,j=2]      (...)

[[i = 2, j=1]]    (...)
a[i = 2, j = 1]   (...)


Can anybody help me?

View this message in context: http://n4.nabble.com/storing-matrix-variables-in-loop-tp1593461p1593461.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list