R as.POSIXct parsing error

I am trying to parse a timeline vector and came across a strange error. For example, if I ran the next 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)

Conclusion:

[1] "2011-03-13 01:00:10 EST"

However, if I changed the time a little before 2 in the morning

t_2 = "03/13/2011 02:00:10"
as.POSIXct(t_2, format = time_format)

Output:

[1] NA

I can play it on R 2.11.1 and 2.12.2 on Windows 7 and XP. Does anyone face the same problem?

Thanks Derek

+3
source share
1 answer

You cannot analyze non-existent times. 02:00:10 did not exist, since we had "spring forward" this Saturday night / Sunday morning with a switch to saving daylight. R knows this:

R> t_1 = "03/13/2011 01:00:10"; as.POSIXct(t_1, format = time_format)
[1] "2011-03-13 01:00:10 CST"
R> t_2 = "03/13/2011 02:00:10"; as.POSIXct(t_2, format = time_format)
[1] "2011-03-13 01:00:10 CST"
R> t_3 = "03/13/2011 03:00:10"; as.POSIXct(t_3, format = time_format)
[1] "2011-03-13 03:00:10 CDT"
R> 

Linux , , - 02:00:10 01:00:10, .

+12

All Articles