Timezone issue when filtering XTS using .indexhour

2019-07-22 19:08发布

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?

标签: r timezone xts
1条回答
Animai°情兽
2楼-- · 2019-07-22 19:48

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

查看更多
登录 后发表回答