Convert days from January 1, 2000 to date format

I have a column in my data for several days since January 1, 2000 (this is 0 days). How to convert the number of days to a date format (2000-01-01)?

Number_of_days    Date
3536              2011-01-03
3537              2011-01-04
3538              2011-01-05
3539              2011-01-06
3540              2011-01-07
3541              2011-01-08

I want to add a new column with a name Datesimilar to the previous one in my df. The number of days above is an example.

+4
source share
1 answer

You need a originparameter as.Date. Using:

as.Date(3536:3541, origin = '2000-01-01')

gives:

[1] "2009-09-06" "2009-09-07" "2009-09-08" "2009-09-09" "2009-09-10" "2009-09-11"

In your case, you can use:

as.Date(df$Number_of_days - 1, origin = '2000-01-01')

or

as.Date(df$Number_of_days, origin = '1999-12-31')
+6
source

Source: https://habr.com/ru/post/1688265/


All Articles