0

I am working with the following dataframe on this:

structure(list(id = 30042:30044, startTime = c("2016-03-13T00:00:00.000Z", 
"2016-03-13T02:00:00.000Z", "2016-03-13T03:00:00.000Z")), row.names = 1022:1024, class = "data.frame")

> mydf
        id                startTime
1022 30042 2016-03-13T00:00:00.000Z
1023 30043 2016-03-13T02:00:00.000Z
1024 30044 2016-03-13T03:00:00.000Z

When i try to convert the startTime column from a character to a time, I get a weird NA appearing:

mydf <- mydf %>%
    dplyr::mutate(startTime = as.POSIXct(startTime, format = '%Y-%m-%dT%H:%M:%S'))

> mydf
     id           startTime
1 30042 2016-03-13 00:00:00
2 30043                <NA>
3 30044 2016-03-13 03:00:00

I am quite lost as to why this is happening, have exhausted my debugging efforts and am simply confused because the format is the exact same for the 3 rows... any help is appreciated!

Edit - this appears to be a daylight savings time issue. What a pain in the ass....

Canovice
  • 9,012
  • 22
  • 93
  • 211
  • March 13 was when daylight saving time ended. There was no 2am that day – MrFlick Nov 28 '18 at 20:48
  • Possibly helpful: https://stackoverflow.com/questions/13865172/handling-data-on-the-days-when-we-switch-to-daylight-savings-time-and-back-in-r – MrFlick Nov 28 '18 at 20:49
  • Duplicate: https://stackoverflow.com/questions/42504670/nexpected-na-after-using-as-posixctstrptime (at least for the specific date in 2016. plenty of other questions come up when you search for "daylight" and "posixct") – MrFlick Nov 28 '18 at 20:50
  • `anytime::anytime(mydf$startTime)` which we can thank @DirkEddelbuettel for – hrbrmstr Nov 28 '18 at 21:02

0 Answers0