[R] Locale problems with strptime to convert dates

Luís Torgo ltorgo at liacc.up.pt
Thu Oct 4 20:39:31 CEST 2001

I'm using R1.3.1 on a x86 machine running Win 2000.

My problem:
- I want to convert a string to a date format using strptime. As I'm from
Portugal my locale information is the following:

> Sys.getlocale()

If I do the following everything works fine :

> k <- "25-Set-01"
> strptime(k,"%d-%b-%y")
[1] "2001-09-25"

because the month September in Portuguese is named "Setembro" and thus is
abbreviated as "set" and not "sep" as in English.

However, I'm interested in reading English dates. I was hoping that the
following would solve my problem:

> Sys.setlocale("LC_TIME", locale="USA")
[1] "English_United States.1252"

However, I get the following error :

> k <- "25-Sep-01"
> strptime(k,"%d-%b-%y")
[1] "NA"

Thank you for any help with this.
Luis Torgo
FEP/LIACC, University of Porto
ltorgo at liacc.up.pt

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list