R xts:同时查询日期和时间 [英] R xts: query both date and time
问题描述
我无法查询 xts 中包含日期和时间范围的子集.例如:
I can't query xts for subsets including both a date and time range. For example:
> head(myxts['2012-01-06 9:30:00/2012-01-06 10:00:00'], 1)
Symbol
2012-01-03 09:30:00 "AA"
> tail(myxts['2012-01-06 9:30:00/2012-01-06 10:00:00'], 1)
Symbol
2012-01-06 10:00:00 "AA"
这里的第一行是 2012-01-03.为什么不是 2012-01-06?
Here the first row is 2012-01-03. Why not 2012-01-06?
编辑
我还尝试先将单个日期提取到新变量中,然后按时间查询.在这种情况下,日期时间序列被正确提取,但时间子集将不起作用.
I've also tried to extract a single date first to a new variable, then query by time. In this case the date timeseries are extracted correctly but the time subset will not work.
e = myxts['2012-01-06']
e['10:00:00::10:20:00'] # returns all rows in '2012-01-06'
编辑 2
发现输入09:45:00"而不是9:45:00"似乎可以解决问题的情况:
Found this situation where entering '09:45:00' rather than '9:45:00' seems to fix the problem:
> tail(myxts['2011-12-19 9:40:00::2011-12-19 9:45:00'])
Symbol DaySec
2011-12-19 16:00:00 "WPI" "57600"
> tail(myxts['2011-12-19 9:40:00::2011-12-19 09:45:00'])
Symbol DaySec
2011-12-19 09:45:00 "WPI" "35100"
推荐答案
'2012-01-06 9:30:00'
不是符合 ISO-8601 的字符串.每个时间分量必须是两位数(如果指定),因此您需要 '2012-01-06 09:30:00'
.
'2012-01-06 9:30:00'
is not an ISO-8601 compliant string. Each time component must be two digits (if specified), so you need '2012-01-06 09:30:00'
.
这篇关于R xts:同时查询日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!