[R-sig-eco] remove elements from a list
Karl Cottenie
cottenie at uoguelph.ca
Tue Sep 29 16:40:01 CEST 2009
Hey,
I want to eliminate certain elements from a list, but when I do this,
the list structure gets completely broken.
> a <- list(list(list(1,2,3)))
> a
[[1]]
[[1]][[1]]
[[1]][[1]][[1]]
[1] 1
[[1]][[1]][[2]]
[1] 2
[[1]][[1]][[3]]
[1] 3
> a[[1]][[1]][-1]
[[1]]
[1] 2
[[2]]
[1] 3
How can I preserve the original list structure, i.e. such that the
output is
[[1]]
[[1]][[1]]
[[1]][[1]][[1]]
[1] 2
[[1]][[1]][[2]]
[1] 3
And why is R doing this, what is the logic for this behaviour?
Thanks a lot,
Karl
----------------------------------------------
Karl Cottenie
Assistant Professor
Integrative Biology
University of Guelph
Guelph, ON, N1G 2W1
cottenie at uoguelph.ca
519 824 4120, ext. 52554
More information about the R-sig-ecology
mailing list