[R] Indexing a loop-created list
Nicolas Prune
np at alambic.org
Wed Oct 18 17:08:20 CEST 2006
Hello,
I create a certain number (n*m) matrices, that I would like to store. These
matrices have different dimensions. As far as I know, for matrices of different
dimensions, there's no alternative to a list.
Here's how I store them on the fly :
my_list <- NULL
for (i in 1:n)
{for (j in (i+1):m)
{my_list <- list(my_list,i_create_a_matrix(i,j)))
}
}
But the indexation of the result is horrible ! (see below a simplified version,
with no matrices created but i*10+j added to the list instead). Is there a
cleaner way to get the same result ?
Any help will be very welcomed.
Nicolas
[[1]]
[[1]][[1]]
[[1]][[1]][[1]]
[[1]][[1]][[1]][[1]]
[[1]][[1]][[1]][[1]][[1]]
[[1]][[1]][[1]][[1]][[1]][[1]]
NULL
[[1]][[1]][[1]][[1]][[1]][[2]]
[1] 12
[[1]][[1]][[1]][[1]][[2]]
[1] 13
[[1]][[1]][[1]][[2]]
[1] 14
[[1]][[1]][[2]]
[1] 23
[[1]][[2]]
[1] 24
[[2]]
[1] 34
More information about the R-help
mailing list