jennie
jennie

Reputation: 23

using POSIXct in R

I have the following code:

as.POSIXct(c('03/08/2015 03:08:18 AM','03/09/2014 02:01:05 AM'),
           format="%m/%d/%Y %l:%M:%S %p")
[1] "2015-03-08 03:08:18 EDT" NA 

Why is the 2nd time returning NA when converted?

Upvotes: 2

Views: 179

Answers (1)

SymbolixAU
SymbolixAU

Reputation: 26258

I see you're working in the EDT (Eastern Daylight Time) time zone

On 09th March 2014 the clocks went forward one hour at 02:00:00. Therefore, the time of 02:01:05 doesn't actually exist.

First you should check the source of the data; should you actually be working in EDT? Most likely not, so you'll want to set the tz argument to the actual timezone.

For example

as.POSIXct(
  c('03/08/2015 03:08:18 AM','03/09/2014 02:01:05 AM')
  , format="%m/%d/%Y %l:%M:%S %p"
  , tz = "EST"   ## change this to the actual timezone you need. 
  )
#"2015-03-08 03:08:18 EST" "2014-03-09 02:01:05 EST"

Upvotes: 1

Related Questions