Skip to content
Prev 5131 / 15274 Next

Discretising intra-day data using zoo?

library(zoo)
print(load(url("http://www.mayin.org/ajayshah/tmp/demo.rda")))
options("digits.secs"=6)
head(demo)
tail(demo)
On Sun, Nov 08, 2009 at 07:20:02AM -0500, Gabor Grothendieck wrote:
Gabor, thanks! I am not as fluent with as.POSIXct() as I should be.

And, to continue with my original question:
How would we do this? To illustrate:

  demo2 <- demo[-300:-700,]
  plot(index(demo2), 1:599, type="l")         # we see that 5th to 10th 
                                              # second is zapped out.
  to5sec <- function(x) as.POSIXct(5*ceiling(as.numeric(x)/5), origin = "1970-01-01")


Now :
spread    ltp
2009-02-16 05:00:05 0.0050 48.715
2009-02-16 05:00:10 0.0025 48.715
2009-02-16 05:00:15 0.0025 48.715
2009-02-16 05:00:20 0.0025 48.715
spread    ltp
2009-02-16 05:00:05 0.0050 48.715
2009-02-16 05:00:15 0.0025 48.715
2009-02-16 05:00:20 0.0025 48.715  

We should get : 

                    spread    ltp
2009-02-16 05:00:05 0.0050 48.715
2009-02-16 05:00:10 NA     NA
2009-02-16 05:00:15 0.0025 48.715
2009-02-16 05:00:20 0.0025 48.715