1

I'm hoping someone can shed light on why a few date/time values are being evaluated by is.na as TRUE when they in fact contain a valid date time value?

dateString = "03/09/14 02:00:00 AM"
dateValue <- strptime(dateString, format='%m/%d/%y %I:%M:%S %p', tz="")
is.na(dateValue)

but one hour earlier or later, and the vast majority of other dates and times, is.na correctly returns FALSE.

Other dateStrings I've experienced this 'error' with include

dateString = "03/08/15 02:30:30 AM"
dateString = "03/13/16 02:25:30 AM"
dooboze
  • 81
  • 8
  • 4
    See [How do I clear an NA flag for a Posix value](http://stackoverflow.com/questions/11529297/how-do-i-clear-an-na-flag-for-a-posix-value). Short answer: possibly a daylight savings issue. `strptime(dateString, format='%m/%d/%y %I:%M:%S %p', tz="GMT")` should return `FALSE` for `is.na(...)`. – Weihuang Wong Oct 21 '16 at 04:57
  • 3
    Also see - http://stackoverflow.com/questions/33092017/formatting-dates-in-r-non-standard-format/33092273 - I suspect daylight savings is the culprit given that Google shows - `2014 Sunday, March 9, 2:00 AM` as the daylight savings roll-forward time for Washington DC – thelatemail Oct 21 '16 at 04:58
  • For instance, `as.POSIXct(dateString, format='%m/%d/%y %I:%M:%S %p', tz="US/Eastern")` gives `NA`. – thelatemail Oct 21 '16 at 05:05
  • And since `is.na.POSIXlt` is just `is.na(as.POSIXct(x))` - you get `NA` even though you otherwise have a date value that can be printed and look normal. – thelatemail Oct 21 '16 at 05:13
  • Thanks @WeihuangWong. Your link helped best because the time is collected in standard time and not being updated for daylight savings time. – dooboze Oct 21 '16 at 05:21
  • 02:00:00 AM is in fact the time when daylight savings time kicks in on March 9 2014 as @thelatemail discovered – dooboze Oct 21 '16 at 05:21

1 Answers1

2

I updated my code to specify the GMT timezone as the data is collected in GMT without a change to or from daylight savings time.

dateValue <- strptime(dateString, format='%m/%d/%y %I:%M:%S %p', tz="GMT")

This ensures properly formatted date time values are not evaluated to TRUE with is.na()

dooboze
  • 81
  • 8