[R] Unexpected date format coercion

Jeremie Juste jerem|eju@te @end|ng |rom gm@||@com
Thu Jul 1 11:00:03 CEST 2021


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



More information about the R-help mailing list