R : Tick data adding value when tick data is missing

r, time-series, xts

Solution

You can merge `price_1m` with an "empty" xts object that contains an index with the regularly-spaced intervals you want, use `na.locf` on that. For example:

onemin <- seq(start(price_1m),end(price_1m),by="1 s")
Price_1m <- na.locf(merge(price_1m, xts(,onemin)))

Problem

I'm working on tick data and want to aggregate my xts irregularly spaced series into a 1 second homogeneous one. I thus use the xts package function to.period : ``` price_1m <-to.period(price,period="seconds",k=1,OHLC=FALSE) ``` here is what I get : ``` 2010-02-02 08:00:03 2787 2010-02-02 08:00:04 2786 2010-02-02 08:00:05 2787 2010-02-02 08:00:06 2787 2010-02-02 08:00:07 2786 2010-02-02 08:00:08 2786 2010-02-02 08:00:09 2786 2010-02-02 08:00:10 2787 2010-02-02 08:00:11 2786 2010-02-02 08:00:14 2786 2010-02-02 08:00:16 2786 2010-02-02 08:00:18 2787 ``` My series is aggregated but for example tick data is missing at times 08:00:13 and 08:00:15. What I want is to fill those blanks with previous tick data knowing that the 08:00:13 and 08:00:15 prices are missing in the tick-by-tick xts series. Any idea? thanks

Original source

Related problems