Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

r - converting "1984-03-25 02:00:00" to POSIX gives NA

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"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...