Ali Roghani
Ali Roghani

Reputation: 509

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"?

Upvotes: 0

Views: 70

Answers (1)

r2evans
r2evans

Reputation: 160437

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.

Upvotes: 1

Related Questions