[R] How to convert European short dates to ISO format?

Kimmo Elo m@||||@t@ @end|ng |rom pp@|net@||
Wed Jun 10 10:30:54 CEST 2020


Hi!

Should it be:

as.Date(oriDates, format="%d/%m/%y") # See the order of %d and %m!!

This command seems to work for me, here the output:

 [1] "2020-01-23" "2020-01-24" "2020-01-25" "2020-01-26" "2020-01-27"
"2020-01-28" "2020-01-29" "2020-01-30"
 [9] "2020-01-31" "2020-02-01" "2020-02-02" "2020-02-03" "2020-02-04"
"2020-02-05" "2020-02-06" "2020-02-07"

HTH,
Kimmo

ke, 2020-06-10 kello 10:20 +0200, Luigi Marongiu kirjoitti:
> Hello,
> I have been trying to convert European short dates formatted as
> dd/mm/yy into the ISO 8601 but the function as.Dates interprets them
> as American ones (mm/dd/yy), thus I get:
> 
> ```
> oriDates = c("23/01/20", "24/01/20", "25/01/20", "26/01/20",
> "27/01/20", "28/01/20", "29/01/20", "30/01/20",
>              "31/01/20", "01/02/20", "02/02/20", "03/02/20",
> "04/02/20", "05/02/20", "06/02/20", "07/02/20")
> isoDates = as.Date(oriDates, format = "%m/%d/%y")
> > isoDates
> 
>  [1] NA           NA           NA           NA           NA
> NA           NA
>  [8] NA           NA           "2020-01-02" "2020-02-02" "2020-03-02"
> "2020-04-02" "2020-05-02"
> [15] "2020-06-02" "2020-07-02"
> ```
> 
> How can I convert properly?



More information about the R-help mailing list