Tuesday, July 31, 2012

Changing system locale in R for locale dependent time string readings

lct <- Sys.getlocale("LC_TIME")
lct
[1] "French_Canada.1252"
strptime(" 27 Jun 2011 19:57:18","%d %b %Y %H:%M:%S") #Does not work
[1] NA
Sys.setlocale("LC_TIME", "C") #Change the locale to C
[1] "C"
strptime(" 27 Jun 2011 19:57:18","%d %b %Y %H:%M:%S") #Now it works
[1] "2011-06-27 19:57:18"
Sys.setlocale("LC_TIME", lct)
[1] "French_Canada.1252"

No comments:

Post a Comment