[R] Locale problems with strptime to convert dates

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


Hi.
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()
[1]
"LC_COLLATE=Portuguese_Portugal.1252;LC_CTYPE=Portuguese_Portugal.1252;LC_MO
NETARY=C;LC_NUMERIC=C;LC_TIME=Portuguese_Portugal.1252"

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
www.liacc.up.pt/~ltorgo

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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