[R] NA and Character(0) in List Element

Gerrit Eichner Gerrit.Eichner at math.uni-giessen.de
Tue Jan 29 10:28:42 CET 2013


Hi, Benjamin,

have you tried for your list with NA-components to use is.na() as follows 
(where x is assumed to be your list)?

x[ !is.na(x)]


  Hth  --  Gerrit

On Tue, 29 Jan 2013, Benjamin Ward (ENV) wrote:

> Hi, This is probably a small query but one I'm struggling with: I have a 
> list in which I had elements which were NA, I removed them, by doing: 
> list2 <- lapply(list, na.omit),
>
> However this leaves the element there with 'character(0)' in place as 
> well as attributes:
>
> e.g.
> [[978]]
> character(0)
> attr(,"na.action")
> [1] 1
> attr(,"class")
> [1] "omit"
>
>
> I want to get rid of these elements/positions in the list, since a 
> function is supposed to sample the list for elements (each element is a 
> collection of about 20 numbers each).
>
> Thanks,
>
> Ben W.
>
> UEA (ENV) - b.ward at uea.ac.uk
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list