I am trying to convert dates into decimal for some purpose and when I need the date in the original format using date_decimal
function, it is not returning the correct actual date.
When I use (tz = "EST")
in date_decimal, it is showing the correct date, but I am not sure what the reason is for its failure in the first place, let alone how it works using "EST".
Can anyone share how lubridate
converts date to decimal and vice versa?!
library(lubridate)
temp <- c('2015-01-01', '2015-02-01', '2015-03-01','2015-04-01', '2015-05-01', '2015-06-01', '2015-07-01', '2015-08-01', '2015-09-01', '2015-10-01', '2015-11-01','2015-12-01')
temp_decimal <- decimal_date(as.Date(temp,format = "%Y-%m-%d"))
temp_date <- as.Date(date_decimal(temp_decimal))
temp_date
[1] "2015-01-01" "2015-01-31" "2015-02-28" "2015-04-01" "2015-04-30" "2015-05-31" "2015-07-01" "2015-07-31" "2015-09-01" "2015-10-01" "2015-10-31" "2015-12-01"
Expected output is:
[1] "2015-01-01" "2015-02-01" "2015-03-01" "2015-04-01" "2015-05-01" "2015-06-01" "2015-07-01" "2015-08-01" "2015-09-01" "2015-10-01" "2015-11-01" "2015-12-01"