quick and dirty, use 'paste' > b <- list() > for (i in 1:3){ + for (j in 1:4){ + a <- matrix(runif(1),3,3) + b[[paste(i,j)]] <- a #but this doesn´t work + } + } > b $`1 1` [,1] [,2] [,3] [1,] 0.2059746 0.2059746 0.2059746 [2,] 0.2059746 0.2059746 0.2059746 [3,] 0.2059746 0.2059746 0.2059746 $`1 2` [,1] [,2] [,3] [1,] 0.1765568 0.1765568 0.1765568 [2,] 0.1765568 0.1765568 0.1765568 [3,] 0.1765568 0.1765568 0.1765568 $`1 3` [,1] [,2] [,3] [1,] 0.6870228 0.6870228 0.6870228 [2,] 0.6870228 0.6870228 0.6870228 [3,] 0.6870228 0.6870228 0.6870228
2010/3/15 Márcio Resende <mresende...@yahoo.com.br> > > 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 > } > b > > 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? > Thanks > > -- > 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. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.