我正在维护一些同时使用lubridate和chron包的代码,并出现了一个新的警告。
警告消息: tz():不知道如何计算类日期/时间对象的时区;返回"UTC“。此警告将成为下一个主要版本的lubridate错误。
这是在从chron制造的物体中提取几个月时产生的。
library(lubridate)
library(chron)
xdate <- structure(c(23831, 23832, 23833, 23834, 23835, 23836),
format = "d/m/y", origin = c(month = 1, day = 1, year = 1900), class = c("dates", "times"))
lubridate::month(xdate)我可以通过在as.Date lubridate::month(as.Date(xdate))中包装xdate来解决这个问题。所产生的日期是正确的。这个方法可以吗?
编辑:我看到了另一种绕过这里的方法是chron::month.day.year(xdate)$month
发布于 2020-05-12 02:13:44
我认为这是可以的,但为了避免出现问题,最好不要使用润滑油。chron有months和monday.day.year,我们还提供了一些其他转换:
as.integer(months(xdate)) # uses chron:::months.default
## [1] 4 4 4 4 4 4
c(months(xdate))
## [1] 4 4 4 4 4 4
month.day.year(xdate)$month # uses chron::month.day.year
## [1] 4 4 4 4 4 4
as.integer(format(as.Date(xdate), "%m"))
## [1] 4 4 4 4 4 4
library(zoo)
cycle(as.yearmon(xdate))
## [1] 4 4 4 4 4 4https://stackoverflow.com/questions/61742294
复制相似问题