'Convert data_numeric to Date in R

I have a dataset that have a numeric date column. How can I convert 2017.31 in a numeric form to the date of "2017-4-22"?



Solution 1:[1]

That may be Apr 23, not the 22nd, but perhaps this is the right start:

vec <- 2017.31
as.POSIXct(paste(trunc(vec), trunc((vec %% 1) * 365)), format = "%Y %j", tz = "UTC")
# [1] "2017-04-23 UTC"

The %j code is described in ?strptime.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 r2evans