跨 DST 日期 Linux 与 Windows 的 XTS 时间子选择
XTS time subselect across DST date Linux vs Windows
在 Windows 上,以下子选择代码生成不正确的 XTS 对象,但在我的 Ubuntu 机器上运行正常
library(xts)
theTimes <- seq(from=as.POSIXct('2016-03-10 12:00:00 CDT'),
to=as.POSIXct('2016-03-20 12:10:00 CDT'),by=60)
ExampleData <- xts(rep(1,length(theTimes)),theTimes)
CutExampleData <- ExampleData['T02:00/T16:00']
any(duplicated(index(CutExampleData))) ## Evaluates to TRUE on windows (incorrect) and FALSE on Ubuntu (correctly)
Linux PC 上的会话信息:
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.1 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RMySQL_0.10.9 DBI_0.5-1 Quandl_2.8.0 xts_0.9-7 zoo_1.7-13
loaded via a namespace (and not attached):
[1] httr_1.2.1 R6_2.1.3 tools_3.3.1 grid_3.3.1 jsonlite_1.0 lattice_0.20-33
Windows PC 上的会话信息:
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 14393)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] xts_0.9-7 zoo_1.7-13
loaded via a namespace (and not attached):
[1] grid_3.3.2 lattice_0.20-34
我认为这与夏令时有关,因为该索引跨越了最近的转换日期。有什么想法吗?
我能够在我的 Windows 机器上复制它。它看起来像在 strptime
and/or as.POSIXct.POSIXlt
之间的 *nix 和 Windows 版本的 R 之间的不正确性。问题出现是因为你的开始时间是 02:00:00,它不由于夏令时,America/Chicago 时区的时间从 01:59:59.999 变为 03:00:00,因此在 2016-03-13 不存在。
一个work-around是把你的开始时间设置在就在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)
另请注意,"CDT" 不是在 R 中指定时区的好方法。three-letter 时区缩写(除了 "GMT" 和 "UTC")可能是模棱两可,所以最好使用Region/City规范。
在 Windows 上,以下子选择代码生成不正确的 XTS 对象,但在我的 Ubuntu 机器上运行正常
library(xts)
theTimes <- seq(from=as.POSIXct('2016-03-10 12:00:00 CDT'),
to=as.POSIXct('2016-03-20 12:10:00 CDT'),by=60)
ExampleData <- xts(rep(1,length(theTimes)),theTimes)
CutExampleData <- ExampleData['T02:00/T16:00']
any(duplicated(index(CutExampleData))) ## Evaluates to TRUE on windows (incorrect) and FALSE on Ubuntu (correctly)
Linux PC 上的会话信息:
R version 3.3.1 (2016-06-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.1 LTS
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RMySQL_0.10.9 DBI_0.5-1 Quandl_2.8.0 xts_0.9-7 zoo_1.7-13
loaded via a namespace (and not attached):
[1] httr_1.2.1 R6_2.1.3 tools_3.3.1 grid_3.3.1 jsonlite_1.0 lattice_0.20-33
Windows PC 上的会话信息:
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 14393)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] xts_0.9-7 zoo_1.7-13
loaded via a namespace (and not attached):
[1] grid_3.3.2 lattice_0.20-34
我认为这与夏令时有关,因为该索引跨越了最近的转换日期。有什么想法吗?
我能够在我的 Windows 机器上复制它。它看起来像在 strptime
and/or as.POSIXct.POSIXlt
之间的 *nix 和 Windows 版本的 R 之间的不正确性。问题出现是因为你的开始时间是 02:00:00,它不由于夏令时,America/Chicago 时区的时间从 01:59:59.999 变为 03:00:00,因此在 2016-03-13 不存在。
一个work-around是把你的开始时间设置在就在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)
另请注意,"CDT" 不是在 R 中指定时区的好方法。three-letter 时区缩写(除了 "GMT" 和 "UTC")可能是模棱两可,所以最好使用Region/City规范。