[R-SIG-Finance] xts question: Extract rows with an NA

Joshua Ulrich josh.m.ulrich at gmail.com
Wed Oct 6 00:08:51 CEST 2010


You could use complete.cases():

> X[!complete.cases(X),]
           [,1] [,2]
2010-10-07    2   NA

Best,
--
Joshua Ulrich
FOSS Trading: www.fosstrading.com



On Tue, Oct 5, 2010 at 5:04 PM, Worik <worik.stanton at gmail.com> wrote:
> On 06/10/10 10:56, Worik wrote:
>>
>> I wish to extract rows from an xts object that have a NA entry.  I can use
>> na.omit to exclude those rows, but I can find no simple way to include them.
>>
>> Is there such a way?
>>
>> > X <- xts(cbind(c(1,2,3), c(1,NA,5)), Sys.Date()+1:3)
>
> OK.  I can say:
>> X[is.na(X[,1]) | is.na(X[,2])]
>           [,1] [,2]
> 2010-10-08    2   NA
>
> This solves my immediate problem.  But is there a generic way that would
> work for any number of columns?
>
> Worik
>
>
> --
> You do not have to be blind to not see what is going on right in front of
> you if it is behind your back
> Pascall West
> --
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>



More information about the R-SIG-Finance mailing list