Hi Maybe you could inspect
parse_date_time {lubridate} R Documentation from package lubridate. Or see answers here https://stackoverflow.com/questions/25463523/how-to-convert-variable-with-mixed-date-formats-to-one-format Cheers Petr > -----Original Message----- > From: Jeremie Juste <jeremieju...@gmail.com> > Sent: Thursday, July 1, 2021 11:00 AM > To: PIKAL Petr <petr.pi...@precheza.cz> > Cc: r-help <r-help@r-project.org> > Subject: Re: [R] Unexpected date format coercion > > Hello > > On Thursday, 1 Jul 2021 at 08:25, PIKAL Petr wrote: > > Hm. > > > > Seems to me, that both your codes are wrong but printing in Linux is > > different from Windows. > > > > With > > as.Date("20-12-2020","%Y-%m-%d") > > you say that 20 is year (actually year 20) and 2020 is day and only > > first two values are taken (but with some valueas result is NA) > > > > I can confirm 4.0.3 in Windows behaves this way too. > >> as.Date("20-12-2020","%Y-%m-%d") > > [1] "0020-12-20" > > Many thanks for confirming this. > > > On Thursday, 1 Jul 2021 at 18:22, Jim Lemon wrote: > > Hi Jeremie, > > Try: > > > > as.Date("20-12-2020","%y-%m-%d") > > [1] "2020-12-20" > > Thanks for this info. I'm looking for something that produce NA if the date > is > not exactly in the specified format so that it can be corrected. I was > relying on > the format parameter of the date for that. > > The issue is that there can be so many variations in date format that for > the > time being I still find it easier to delegate the correction to the user. A > particular nasty case is when there are multiple date format in the same > column. > > > Best regards, > Jeremie
______________________________________________ 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.