[R-SIG-Finance] How to remove NA from an xts object (NAs appear in the index )
Joshua Ulrich
josh.m.ulrich at gmail.com
Sun Sep 26 17:47:37 CEST 2010
On Sun, Sep 26, 2010 at 9:52 AM, Paulo Grahl <pgrahl at gmail.com> wrote:
> Dear all,
> I've downloaded the following exchange rate data from FRED
>
> library(quantmod)
> getSymbols("DEXBZUS",src="FRED")
>
> And it happens that there are a couple of NA's, not in the data, but in the
> index(DEXBZUS).
Are you doing something after downloading and before checking the
index for NA values? I ask because there are no NA index values when
I download the data.
> getSymbols("DEXBZUS",src="FRED")
[1] "DEXBZUS"
> sum(is.na(index(DEXBZUS)))
[1] 0
> Using na.omit() does not exclude these data points from the time series.
> I could obviously exclude this points by searching the index() of the
> series, but I was wondering if xts already has some functionality that could
> handle these cases.
You can do this by using is.na() on the index:
> (x <- xts(1:10,as.Date(c(1:9,NA))))
[,1]
1970-01-02 1
1970-01-03 2
1970-01-04 3
1970-01-05 4
1970-01-06 5
1970-01-07 6
1970-01-08 7
1970-01-09 8
1970-01-10 9
<NA> 10
> x[!is.na(index(x))]
[,1]
1970-01-02 1
1970-01-03 2
1970-01-04 3
1970-01-05 4
1970-01-06 5
1970-01-07 6
1970-01-08 7
1970-01-09 8
1970-01-10 9
HTH,
--
Joshua Ulrich
FOSS Trading: www.fosstrading.com
> Thanks
> Paulo
>
>
> --
> Paulo Gustavo Grahl, CFA
> ------------------------------------------
> pgrahl at gmail.com
> pgrahl at fgvmail.br
> +55(21) 8809-9254
> skype:paulo.grahl
> www.linkedin.com/in/pgrahl
> ------------------------------------------
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> 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