Thank you. It worked. Case closed On Thu, 11 Jun 2020, 16:48 Rasmus Liland, <j...@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]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.