1

Possible Duplicate:
XTS apply function to time of day subset?

I'm interested in this kind of pattern: does something interesting happen each day between 09:45 and 09:55 [regardless if it's this day or the other]. I'm using xts, but I can't find a way to disregard the date, and use only the time for this analysis.

Here's some code as an example:

times = c(as.POSIXct("2012-11-03 09:45:00 IST"),
          as.POSIXct("2012-11-04 09:45:00 IST"),
          as.POSIXct("2012-11-05 12:45:00 IST"),
          as.POSIXct("2012-11-08 09:45:01 IST"))

xts.obj = xts(c(1,2,3,4),order.by = times)

#the resulting xts object:
#2012-11-03 09:45:00    1
#2012-11-04 09:45:00    2
#2012-11-05 12:45:00    3
#2012-11-08 09:45:01    4

My aim is to be able to aggregate e.g. (09:45-09:55), regardless of day. this would result in entries (1,2,4): they all take place in this time range [on different dates]

Thanks a lot.

Community
  • 1
  • 1
zuuz
  • 859
  • 1
  • 12
  • 23
  • 1
    Please search before posting. The query "[r] xts time of day" yields [R xts object subseting xts object with multiple days of intraday data for certain hours](http://stackoverflow.com/q/7239146/271616) and [xts tick data rolling subset](http://stackoverflow.com/q/7157174/271616) in the first 10 results. – Joshua Ulrich Dec 31 '12 at 13:41

1 Answers1

3

Using time-of-day subsetting:

xts.obj["T09:45/T09:55"] 
                    [,1]
2012-11-03 09:45:00    1
2012-11-04 09:45:00    2
2012-11-08 09:45:01    4
agstudy
  • 119,832
  • 17
  • 199
  • 261