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

Luigi Marongiu m@rong|u@|u|g| @end|ng |rom gm@||@com
Fri Jun 12 08:45:15 CEST 2020


Thank you. It worked. Case closed

On Thu, 11 Jun 2020, 16:48 Rasmus Liland, <jral using posteo.no> wrote:

> On 2020-06-10 10:20 +0200, Luigi Marongiu wrote:
> > 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)
>
> Dear Luigi,
>
> ?strptime says:
>
>         ‘%D’ Date format such as ‘%m/%d/%y’: the C99 standard says it
>              should be that exact format (but not all OSes comply).
>
> as.Date(oriDates, format="%d/%m/%y") works
> fine for me here on the Linux laptop ...
>
> You could also try to work on the strings
> themselves to convert them to ISO format,
> like:
>
>         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")
>         d <- t(as.data.frame(strsplit(oriDates, "/")))
>         dimnames(d) <- list(NULL, c("d", "m", "y"))
>         u <- unique(d[,"y"])
>         millenia <- "20"
>         if (length(u)==1 & u==millenia) {
>           Dates <- paste0(millenia, d[,"y"], "-",
>                           d[,"m"], "-", d[,"d"])
>           Dates <- as.Date(Dates)
>         } else {
>           Dates <- "'Allo 'allo ... error, error ... more complicated
> formatting is required to digest those dates ..."
>         }
>         print(Dates)
>
> Best,
> Rasmus
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list