[R-sig-eco] remove elements from a list
Glen Sargeant
gsargeant at usgs.gov
Wed Sep 30 18:11:06 CEST 2009
Karl Cottenie wrote:
>
> 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)))
>
> 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?
>
>
Try this, Karl:
> a <- list(list(list(1,2,3)))
> a[[1]][[1]][1] <- NULL
> a
[[1]]
[[1]][[1]]
[[1]][[1]][[1]]
[1] 2
[[1]][[1]][[2]]
[1] 3
Good luck!
Glen
-----
Glen Sargeant
Research Wildlife Biologist
--
View this message in context: http://n2.nabble.com/remove-elements-from-a-list-tp3736681p3743639.html
Sent from the r-sig-ecology mailing list archive at Nabble.com.
More information about the R-sig-ecology
mailing list