R xts对象使用多天的日内数据对特定小时进行子对话xts对象

时间:2011-08-30 05:46:12

标签: r subset xts

xts对象中是否有一种方法可以执行与下面相同的操作,但对于具有多天日内数据的xts对象?下面的工作就像一个时钟,但有一天的数据。如果我将xts从第22位传递到第26位则没有。看起来像是在多天内以xts为单位对日内数据进行分段是不可能一次完成的,而是需要先每天分割数据然后再使用这个xts功能。它是否正确?

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 个答案:

答案 0 :(得分:2)

xts具有时间分组:xts tick data rolling subset

tdata['T10:00:00/T12:00:00']应该这样做。