[R] Unexpected date format coercion

PIKAL Petr petr@p|k@| @end|ng |rom prechez@@cz
Thu Jul 1 10:25:03 CEST 2021


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"

Cheers
Petr


> -----Original Message-----
> From: R-help <r-help-bounces using r-project.org> On Behalf Of Jeremie Juste
> Sent: Thursday, July 1, 2021 10:06 AM
> To: r-help <r-help using r-project.org>
> Subject: [R] Unexpected date format coercion
> 
> Hello,
> 
> I have been surprised when converting a character string to a date with
the
> following format,
> 
> in R 4.1.0 (linux debian 10)
> 
> as.Date("20-12-2020","%Y-%m-%d")
> [1] "20-12-20"
> 
> in R 4.0.5 (window 10)
> 
> as.Date("20-12-2020","%Y-%m-%d")
> [1] "0020-12-20"
> 
> 
> Here I was expecting a blunt and sharp NA, am I missing something?
> 
> Best regards,
> Jeremie
> 
> ______________________________________________
> R-help using 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.


More information about the R-help mailing list