I have a column in my data as a number of days since Jan 1, 2000 (this is 0 day). How can I convert day number into 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 called Date
similar to above one into my df. Number of days to Date above is just an example.
You need the origin
-parameter of 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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With