[R] Indexing a loop-created list

From: Nicolas Prune <np_at_alambic.org>
Date: Wed 18 Oct 2006 - 15:08:20 GMT


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



R-help@stat.math.ethz.ch 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. Received on Fri Oct 20 10:28:49 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 20 Oct 2006 - 01:30:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.