[R] Results of applying na.omit on zoo object

Achim Zeileis Achim.Zeileis at uibk.ac.at
Mon Sep 19 19:05:07 CEST 2011


On Mon, 19 Sep 2011, Rich Shepard wrote:

> On Mon, 19 Sep 2011, Marc Schwartz wrote:
>
>> You can look at ?complete.cases for one approach, presuming that it will
>> work on zoo objects.
>
> Marc,
>
>  That's the opposite of what I want. It returns only rows with no missing
> data. I'm looking for something that will return rows with _only_ missing
> data, and drop them in the bit bucket.

This should do what you want, I think:

R> z <- zoo(matrix(1:8, ncol = 2), Sys.Date() + 0:3)
R> z[2,2] <- NA
R> z[3,] <- NA
R> z

2011-09-19  1  5
2011-09-20  2 NA
2011-09-21 NA NA
2011-09-22  4  8

R> z[!apply(is.na(z), 1, all),]

2011-09-19 1  5
2011-09-20 2 NA
2011-09-22 4  8

hth,
Z

> Thanks,
>
> Rich
>
> ______________________________________________
> 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