fifthace fifthace - 27 days ago 7
R Question

Using as.POSIXct in R giving na for identical character structures

I have two timestamps in character form that I want to convert to a POSIX format in R.
The

timestamps
are:

1: "2013-03-30 17:45:00"

2: "2013-03-31 02:05:00"


The first one converts fine, the second one gives me
NA
. The
timestamps
are downloaded as
characters
from an
SQL server
. Anyone have any ideas what is going wrong?

I don't have the reputation to attach a screenshot, so a screenshot of my R console showing the result is provided here: http://emillarsen.com/r%20console.jpg

Answer

It looks like a DST issue. I assume from your name you are from Sweden or thereabouts. There was no time in Sweden between 2am and 3am on the 31st March 2013, as the clocks went forward then.

as.POSIXct("2013-03-31 02:05:00",format="%Y-%m-%d %H:%M:%S", tz="Europe/Stockholm")
[1] NA

This is true for anyone on Central European Time (CET).

Comments