Timezone issue when filtering XTS using .indexhour

对着背影说爱祢 提交于 2019-12-11 02:59:06

问题


The following R code returns an unexpected output:

times = c("2014-12-01 15:59:00", "2014-12-01 16:00:00", "2014-12-01 16:01:00")
values = c(64.23, 64.43, 64.31)
tim <- as.POSIXct(c("2014-12-01 15:59:00", "2014-12-01 16:00:00", "2014-12-01 16:01:00"), tz="GMT")
myts <- xts(values, tim, tzone="GMT")
print(myts[.indexhour(myts)==16])

I get:

                     [,1]
2014-12-01 15:59:00 64.23

While I would expect:

                     [,1]
2014-12-01 16:00:00 64.43
2014-12-01 16:01:00 64.31

I think .indexhour is somehow referring to my local timezone, while I obviously expect it to use the XTS object timezone.

Is there anything I can do to fix it?


回答1:


This is bug #5891 and has been patched on R-Forge as of revision 844.



来源:https://stackoverflow.com/questions/27943770/timezone-issue-when-filtering-xts-using-indexhour

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