Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

timestamp

r

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

like image 519
fifthace Avatar asked Jan 16 '14 11:01

fifthace


Video Answer


1 Answers

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).

like image 191
James Avatar answered Nov 14 '22 23:11

James