R as.POSIXct 解析错误
我正在尝试解析时间字符串向量并遇到一个奇怪的错误。例如,如果我运行以下代码部分,R 将按预期返回结果。
time_format="%m/%d/%Y %H:%M:%S"
t_1 = "03/13/2011 01:00:10"
as.POSIXct(t_1, format = time_format)
输出:
[1] "2011-03-13 01:00:10 EST"
但是,如果我将时间稍微更改为凌晨 2 点,
t_2 = "03/13/2011 02:00:10"
as.POSIXct(t_2, format = time_format)
输出将变为:
[1] NA
我可以在 Windows 7 和 XP 上的 R 2.11.1 和 2.12.2 上重现它。有人遇到同样的问题吗?
谢谢, 德里克
I am trying to parse a vector of time string and came across a strange error. For example, if I run the following section of code, R returned the result as expected.
time_format="%m/%d/%Y %H:%M:%S"
t_1 = "03/13/2011 01:00:10"
as.POSIXct(t_1, format = time_format)
Output:
[1] "2011-03-13 01:00:10 EST"
However, if I change the time slightly to 2 AM
t_2 = "03/13/2011 02:00:10"
as.POSIXct(t_2, format = time_format)
The output became:
[1] NA
I can reproduce it on R 2.11.1 and 2.12.2 on Windows 7 and XP. Does anyone encounter the same problem?
Thanks,
Derek
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法解析不存在的时间。 02:00:10 不存在,因为我们在本周六晚上/周日早上切换到夏令时,“向前迈进”。 R 知道这一点:
在 Linux 上,我的时区库似乎可以应付——减去一小时后,02:00:10 变成 01:00:10。
You cannot parse non-existing times. 02:00:10 did not exist as we had 'spring forward' this Saturday night / Sunday morning with the switch to daylight-savings. R knows this:
On Linux, my timezone library seems to cope -- 02:00:10 becomes 01:00:10 as an hour is subtracted.