date_decimal问题

时间:2019-04-04 08:47:18

标签: r date lubridate

出于某种目的,我试图将日期转换为十进制,并且当我需要使用date_decimal函数以原始格式显示日期时,它没有返回正确的实际日期。

当我在date_decimal中使用(tz = "EST")时,它显示的是正确的日期,但我不确定首先导致失败的原因是什么,更不用说它如何使用“ EST”了。

任何人都可以分享lubridate如何将日期转换为十进制,反之亦然吗?!

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"

预期输出为:

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

0 个答案:

没有答案