[R] Filling missing days in xts time series

R. Michael Weylandt michael.weylandt at gmail.com
Sat Oct 8 17:37:20 CEST 2011


Can you provide an example of where using the zoo methods directly on
the xts object fails to work? You'll note that

R> X = xts(1:5, Sys.Date()+(1:5)/2)

R> class(X)
[1] "xts" "zoo"

so the zoo methods should work automatically. This gives you access to
all sorts of options for handling NAs.

Michael

On Sat, Oct 8, 2011 at 6:53 AM, thierrydb <thierrydb at gmail.com> wrote:
> Hi,
>
>
> I have a bunch of irregularly spaced xts time series (with a POSIX index),
> and I'm trying to write a function that fillls the missing days. Using a
> solution suggested by Gabor Grothendieck for zoo, I wrote the following:
>
> # FD: Fill missing days
> FD<-function(ser) {rng<-range(time(ser))
>> temp<-merge(ser,xts(,seq(rng[1],rng[2],"day")))
>> na.locf(temp,fromLast=TRUE)
>
> However,using S&P end-of-day time series, I obtain doubled entries such as:
>
> 2011-09-29 00:00:00 1160.40
> 2011-09-29 02:00:00 1131.42
> 2011-09-30 00:00:00 1131.42
> 2011-09-30 02:00:00 1099.23
> 2011-10-01 02:00:00 1099.23
> 2011-10-02 02:00:00 1099.23
>
> It looks like it is due to the way xts handles time zones. What is the
> correct way to do this?
>
>
> Thanks
>
> TDB
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Filling-missing-days-in-xts-time-series-tp3884830p3884830.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.
>



More information about the R-help mailing list