Às 05:23 de 28/07/2024, akshay kulkarni escreveu:
Dear members,
                              WHy is the following code returning NA instead of 
the date?


as.Date("2022-01-02", origin = "1900-01-01",  format = "%y%d%m")
[1] NA


Thanking you,
Yours sincerely,
AKSHAY M KULKARNI

        [[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.
Hello,

There are several reasons for your result.

1. You have 4 digits year but format %y (lower case = 2 digits year) It should be %Y
2. Your date has '-' as separator but your format doesn't have a separator.

Also, though less important:

1. You don't need argument origin. This is only needed with numeric to date coercion.
2. Are you sure the format is YYYY-DD-MM, year-day-month?


as.Date("2022-01-02", format = "%Y-%d-%m")
#> [1] "2022-02-01"

# note the origin is not your posted origin date,
# see the examples on Windows and Excel
# dates in help("as.Date")
as.Date(19024, origin = "1970-01-01")
#> [1] "2022-02-01"


Hope this helps,

Rui Barradas


--
Este e-mail foi analisado pelo software antivírus AVG para verificar a presença 
de vírus.
www.avg.com

______________________________________________
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.

Reply via email to