[R] lists within a list / data-structure problem

Jan Wantia wantia at ifi.unizh.ch
Mon Dec 13 16:59:48 CET 2004

Dear all,

this is a rather basic question; i am not sure how to structure my data
I want to extraxt various measures from my raw-data. These measures are
of different sizes, so I decided to store them in a list, like:

run1 <- list(Dom = (my_vector), mean = (my_single_number))

I can do that in a for loop for 40 runs, ending up with 40 lists: run1,
run2, ..., run40.
To have all the measurements neatly together I thought of making another
list, containing  40 sub-lists:

 > ALL <- list(run1, run2,..., run40)
 > ALL
[1] "my_vector"

[1] "my_single_number"

[1] "my_vector"

[1] "my_single_number"


1) This may be a bit clumsy as I have to type all the sub-list's names
in by hand in order to produce my ALL-list: Is there a better way?

2) I have problems of addressing the data now. I can easily access any
single value; for example, for the second component of the second sub- list:

 > ALL[[2]][[2]]
[1] "my_single_number",

but: how could I get the second component of all sub-lists, to plot, for
example, all the $mean in one plot? For a matrix, mat[,2] would give me
the whole second column, but
does not return all the second components.

I feel that 'lapply' might help me here, but I could not figure out
exactly how to use it, and it always comes down to the problem of how to
correctly address the components in the sublists.

Or is there maybe a smarter way to do that instead of using a list of lists?

Any hint would be warmly appreciated!

(R 2.0.1 on windows XP)



Jan Wantia
Deptartment of Informatics, University of Zurich
Andreasstr. 15
CH 8050 Zurich

Tel.:    +41 (0) 1 635 4315
Fax:     +41 (0) 1 635 45 07
email: wantia at ifi.unizh.ch

More information about the R-help mailing list