2
votes

Hi I'm using the lubridate package and I want to convert a vector from 1:365 (day of year) in a date format:

e.g. 60 -> 2019-03-01 UTC.

For 1-99 it works fine, but for 100-365 I get a warning massage.

lubridate::parse_date_time(99, "j")
[1] "2019-04-09 UTC"

lubridate::parse_date_time(100:365, "j")
[1] NA ...
[365] NA

Warning message:
All formats failed to parse. No formats found.

Gets anyone the same warning massage or has a solution?

2

2 Answers

1
votes

If you provide character input, it works well

lubridate::parse_date_time('100', "j")
# [1] "2019-04-10 UTC"
lubridate::parse_date_time(paste(100:365), "j")
# [1] "2019-04-10 UTC" "2019-04-11 UTC" "2019-04-12 UTC" "2019-04-13 UTC" "2019-04-14 UTC" "2019-04-15 UTC" "2019-04-16 UTC" "2019-04-17 UTC"
# ...
# [265] "2019-12-30 UTC" "2019-12-31 UTC
1
votes

you can easily do it with specifying origin date using

as.Date(100:365, format = "%j", origin = "01-01-2019")