XTS time subselect across DST date Linux vs Windows

岁酱吖の 提交于 2019-12-02 04:35:33

I was able to replicate this on my Windows machine. It looks like an infelicity in strptime and/or as.POSIXct.POSIXlt between *nix and Windows versions of R. The problem manifests because your start time is 02:00:00, which doesn't exist on 2016-03-13 because times go from 01:59:59.999 to 03:00:00 in the America/Chicago timezone due to daylight saving time.

A work-around is to set your start time to just before 02:00:00.

library(xts)
theTimes <- seq(from=as.POSIXct('2016-03-12 00:00:00', tz="America/Chicago"),
                to=as.POSIXct('2016-03-14 23:00:00', tz="America/Chicago"), by=60)
ExampleData <- xts(rep(1,length(theTimes)),theTimes)
# 01:59 instead of 02:00 to avoid DST issue
CutExampleData <- ExampleData['T01:59/T16:00']
anyDuplicated(index(ExampleData))
anyDuplicated(index(CutExampleData))  # 0 (no duplicates)

Also note that "CDT" is not a good way to specify a timezone in R. The three-letter timezone abbreviations (aside from "GMT" and "UTC") may be ambiguous, so it's better to use the Region/City specification.

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