0

Trying to convert chr to a proper date format in R, I use the following example, returning an error.

> as.POSIXlt(strptime("Tue, 23 Mar 2010 14:36:38 -0400", "%a, %d %b %Y %H:%M:%S %z"))
[1] NA
Paavo Pohndorff
  • 323
  • 1
  • 2
  • 17

1 Answers1

0

Following the comments on as.POSIXlt is producing NA in R I realized I have the wrong LC_TIME set for my session.

> Sys.getlocale("LC_TIME")
[1] "German_Germany.1252"

The format above is in English and not in German. So changing the locale should be the solution and voilà!

> Sys.setlocale("LC_TIME", "English")
[1] "English_United States.1252"
> as.POSIXlt(strptime("Tue, 23 Mar 2010 14:36:38 -0400", "%a, %d %b %Y %H:%M:%S %z"))
[1] "2010-03-23 19:36:38"
Paavo Pohndorff
  • 323
  • 1
  • 2
  • 17