Skip to content
Prev 16315 / 398500 Next

list indexing

Hello

I've got a question about  list indexing. If anyone can help or point 
in the direction of some documentation, that'd be great. I've checked 
the Introduction to R and R language definition.

Say you have a list of vectors:
[[1]]
[1] "a" "b" "c"

[[2]]
[1] "a" "b" "c" "d"

[[3]]
[1] "a" "b"

[[4]]
[1] "a" "b" "c" "d" "e"

Indexing single list components is fine using [[i]] and elements 
within using [[i]][j] but what if you want to get some information, 
for instance vector length or attributes of the components, across 
(or should that be down) the top level components. You can do it by 
looping across 1:length(list):
[1] 3 4 2 5

I know it's only two lines of code. I  guess I'm wondering whether 
there is something that does what I'd expect from length(x[[1:4]]) if 
[[i]] allowed multiple indices.

Thanks,
David Orme.