converting “1984-03-25 02:00:00” to POSIX gives NA

倾然丶 夕夏残阳落幕 提交于 2019-11-28 10:35:41

问题


While converting a vector of date-time to POSIXlt, just one particular time "25-Mar-1984-02:00" "is converted to POSIXlt but returns NA! So, this row was getting omitted in my analysis/plots.

is.na(as.POSIXlt("25-Mar-1984-02:00",format = "%d-%b-%Y-%H:%M"))
is.na(as.POSIXlt("25-Mar-1984-03:00",format = "%d-%b-%Y-%H:%M"))
is.na(as.POSIXlt("25-Mar-1984-01:00",format = "%d-%b-%Y-%H:%M"))
is.na(as.POSIXlt("24-Mar-1984-02:00",format = "%d-%b-%Y-%H:%M"))
is.na(as.POSIXlt("26-Mar-1984-02:00",format = "%d-%b-%Y-%H:%M"))

returns TRUE, FALSE, FALSE, FALSE, FALSE.

but

class(as.POSIXlt("25-Mar-1984-02:00",format = "%d-%b-%Y-%H:%M"))

returns [1] "POSIXlt" "POSIXt"

Isn't that strange? How can I get it to be "not NA"?


回答1:


While you don't say what your timezone is, this looks like Daylight Saving Time (DST) issue. In timezones that use DST, there will be a day where the hour "jumps" from 1:59:59.999 to 3:00:00.000. This means that any times in the 2AM hour do not exist on this day.

My guess is that 1984-03-25 02:00:00 is when DST occurs in your local timezone.



来源:https://stackoverflow.com/questions/30807033/converting-1984-03-25-020000-to-posix-gives-na

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