[R] avoid NA in list

Peter Alspach Peter.Alspach at plantandfood.co.nz
Sun Sep 6 23:26:46 CEST 2009


Tena koe

Alternatively, for instances where you have a list element which is a vector of all NA:

> grzes <- list(a=1:4, b=NA, c=letters[1:5], d=c(1,NA,10), e=rep(NA,5))
> grzes
$a
[1] 1 2 3 4

$b
[1] NA

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

$d
[1]  1 NA 10

$e
[1] NA NA NA NA NA

> grzes[sapply(grzes, function(x) !all(is.na(x)))]
$a
[1] 1 2 3 4

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

$d
[1]  1 NA 10

> grzes[!is.na(grzes)]
$a
[1] 1 2 3 4

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

$d
[1]  1 NA 10

$e
[1] NA NA NA NA NA


HTH ...

Peter Alspach
> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Henrique 
> Dallazuanna
> Sent: Monday, 7 September 2009 8:37 a.m.
> To: Grzes
> Cc: r-help at r-project.org
> Subject: Re: [R] avoid NA in list
> 
> Try this:
> 
> your_list[!is.na(your_list)]
> 
> On Sun, Sep 6, 2009 at 4:32 PM, Grzes <gregorio99 at gmail.com> wrote:
> 
> >
> > Hi!
> > I Have list, for example:
> > ...
> > [[22]]
> > [1]  27  51  69 107 119
> >
> > [[23]]
> > [1] NA
> >
> > [[24]]
> > [1] 54 57 62
> >
> > And I would like to avoid NA value. Similar way like I may do it in 
> > vector using na.value() function.
> > Do you have any idea?
> > --
> > View this message in context:
> > http://www.nabble.com/avoid-NA-in-list-tp25321020p25321020.html
> > Sent from the R help mailing list archive at Nabble.com.
> >
> > ______________________________________________
> > 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.
> >
> 
> 
> 
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
> 
> 	[[alternative HTML version deleted]]
> 
> 




More information about the R-help mailing list