[R] Format dates issues with R
Ivan Calandra
c@|@ndr@ @end|ng |rom rgzm@de
Tue Dec 14 11:59:54 CET 2021
Dear Luigi,
Quickly, I spot two problems:
1) "09/20/2021" can only be month/day/year (and not day/month/year as
you specified).
2) The year is given with century, so it should be upper case Y
So
as.Date(ori[[n[3]]], format = "%m/%d/%Y")
should work.
HTH,
Ivan
--
Dr. Ivan Calandra
Imaging lab
RGZM - MONREPOS Archaeological Research Centre
Schloss Monrepos
56567 Neuwied, Germany
+49 (0) 2631 9772-243
https://www.researchgate.net/profile/Ivan_Calandra
On 14/12/2021 11:54, Luigi Marongiu wrote:
> Hello,
> I have these kind of dates:
> ```
>> ori[[n[3]]]
> [1] "9/20/2021" "9/20/2021" "9/20/2021" "9/20/2021" "9/20/2021" "9/20/2021"
> [7] "9/20/2021" "9/20/2021" "9/20/2021" "9/20/2021" "9/21/2021" "9/21/2021"
> [13] "9/21/2021" "9/21/2021" "9/21/2021" "9/21/2021" "9/21/2021" "9/21/2021"
> [19] "9/21/2021" "9/21/2021" "9/22/2021" "9/22/2021" "9/22/2021" "9/22/2021"
> [25] "9/22/2021" "9/22/2021" "9/22/2021" "9/22/2021" "9/22/2021" "9/22/2021"
> [31] "9/23/2021" "9/23/2021" "9/23/2021" "9/23/2021" "9/23/2021" "9/23/2021"
> [37] "9/23/2021" "9/23/2021" "9/23/2021" "9/23/2021" "9/24/2021" "9/24/2021"
> [43] "9/24/2021" "9/24/2021" "9/24/2021" "9/24/2021" "9/24/2021" "9/24/2021"
> [49] "9/24/2021" "9/24/2021" "9/27/2021" "9/27/2021" "9/27/2021" "9/27/2021"
> [55] "9/27/2021" "9/27/2021" "9/27/2021" "9/27/2021" "9/27/2021" "9/27/2021"
> [61] "9/28/2021" "9/28/2021" "9/28/2021" "9/28/2021" "9/28/2021" "9/28/2021"
> [67] "9/28/2021" "9/28/2021" "9/28/2021" "9/28/2021" "9/29/2021" "9/29/2021"
> [73] "9/29/2021" "9/29/2021" "9/29/2021" "9/29/2021" "9/29/2021" "9/29/2021"
> [79] "9/29/2021" "9/29/2021" "10/1/2021" "10/1/2021"
> ```
> they look to me as month, date, year so I formatted them as:
> ```
>> as.Date(ori[[n[3]]], format = "%D")
> # or: as.Date(ori[[n[3]]], format = "%d/%m/%y")
> [1] NA NA NA NA NA
> NA
> [7] NA NA NA NA NA
> NA
> [13] NA NA NA NA NA
> NA
> [19] NA NA NA NA NA
> NA
> [25] NA NA NA NA NA
> NA
> [31] NA NA NA NA NA
> NA
> [37] NA NA NA NA NA
> NA
> [43] NA NA NA NA NA
> NA
> [49] NA NA NA NA NA
> NA
> [55] NA NA NA NA NA
> NA
> [61] NA NA NA NA NA
> NA
> [67] NA NA NA NA NA
> NA
> [73] NA NA NA NA NA
> NA
> [79] NA NA "2010-01-20" "2010-01-20"
> ```
> Why the conversion did not work?
> Thank you
>
> ______________________________________________
> 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