Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...