Reputation: 23
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?
Upvotes: 2
Views: 202
Reputation: 1595
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
Upvotes: 1
Reputation: 1443
you can easily do it with specifying origin date using
as.Date(100:365, format = "%j", origin = "01-01-2019")
Upvotes: 1