[R] Filling missing days in xts time series

thierrydb thierrydb at gmail.com
Sat Oct 8 12:53:16 CEST 2011


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.



More information about the R-help mailing list