XTS time subselect across DST date Linux vs Windows

前端 未结 1 1530
鱼传尺愫
鱼传尺愫 2021-01-24 09:39

On Windows the following subselect code produces an incorrect XTS object, but works correctly on my Ubuntu machine

library(xts)
theTimes <- seq(from=as.POSIXc         


        
相关标签:
1条回答
  • 2021-01-24 10:25

    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.

    0 讨论(0)
提交回复
热议问题