请考虑以下内容:
library(lubridate)
period1 = weeks(2)
as.numeric(period1, "weeks")
> 2 # as expected
现在我正在尝试用月份做类似的事情:
period2= months(6)
as.numeric(period2, "months")
as.numeric(period2, "weeks")
> 26.08929 # OK
as.numeric(period2,"months")
> 0.04166667 # Not OK?
这是 lubridate
的一个 bug 吗?还是我做错/漏掉了什么?
注意:我看到(旧的)评论:Have lubridate subtraction return only a numeric value,所以我猜我也可以使用 difftime
来解决问题,但我想坚持使用 lubridate。
seconds_to_unit
或period_to_seconds
可能值得探索。 - Roman Luštrik