R xts object subseting xts object with multiple days of intraday data for certain hours

♀尐吖头ヾ 提交于 2019-12-06 06:59:45

问题


Is there a way in xts object to do the same as below but for xts object with multiple days of intraday data? The below works like a clock but for one day of data. If I pass xts from 22nd to 26th it does not. It seems like subseting intraday data in xts across multiple days is not possible to be done in one go but rather need to first split data per each day and then use this xts functionality. Is this correct?

indexTZ(tdata) = "GMT"
plotdata= tdata['20110822 10:00:00/20110822 12:00:00']

> plotdata= tdata['10:00:00/12:00:00'] works like swiss clock


> tail(plotdata)
                SYMBOL EX  PRICE              SIZE    COND CORR G127
2011-08-22 11:59:36 "BHP"  "N" "38370"            "185"   "1"  "0"  "0" 
2011-08-22 11:59:37 "BHP"  "N" "38380"            "314"   "1"  "0"  "0" 
2011-08-22 11:59:40 "BHP"  "N" "38390"            "675"   "1"  "0"  "0" 
2011-08-22 11:59:42 "BHP"  "N" "38390"            "119"   "1"  "0"  "0" 
2011-08-22 11:59:43 "BHP"  "N" "38390"            "359"   "1"  "0"  "0" 
2011-08-22 11:59:44 "BHP"  "N" "38400.7702920749" "42763" "1"  "0"  "0" 

 plotdata= tdata['10:00:00/12:00:00'] or 
 plotdata= tdata['20110822 10:00:00/20110826 12:00:00'] does not return expected xts 

tail(plotdata)
                SYMBOL EX  PRICE              SIZE   COND CORR G127
2011-08-26 15:59:53 "BHP"  "N" "38710"            "119"  "1"  "0"  "0" 
2011-08-26 15:59:55 "BHP"  "N" "38700"            "1004" "1"  "0"  "0" 
2011-08-26 15:59:56 "BHP"  "N" "38700.4838709677" "310"  "1"  "0"  "0" 
2011-08-26 15:59:57 "BHP"  "N" "38710"            "6"    "1"  "0"  "0" 
2011-08-26 15:59:58 "BHP"  "N" "38710"            "2"    "1"  "0"  "0" 
2011-08-26 15:59:59 "BHP"  "N" "38710"            "121"  "9"  "0"  "0" 

回答1:


xts has time-of-day subsetting: xts tick data rolling subset

tdata['T10:00:00/T12:00:00'] should do.



来源:https://stackoverflow.com/questions/7239146/r-xts-object-subseting-xts-object-with-multiple-days-of-intraday-data-for-certai

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!