对于下面的代码,我得到了错误的季度。请帮我解决这个问题
qy= cut.POSIXt(as.POSIXct(c("2015-09-01 IST","2016-08-1 IST")), breaks="quarter", labels=FALSE,include.lowest=T)
qy
# [1] 1 5
发布于 2018-10-11 13:33:58
cut.POSIXt
(带有labels=FALES
)向您提供相对于min(X)
季度的季度数-它从最早的日期开始,并告诉您每个日期和该日期之间的季度数。因此,当您给出连续两年的Q3日期时,第一个是1,第二个是4个季度后,即5。
如果您尝试获取一年内每个日期的季度,请使用quarters
或lubridate::quarter
quarters(as.POSIXct(c("2015-09-01 IST","2016-08-1 IST")))
[1] "Q3" "Q3"
lubridate::quarter(as.POSIXct(c("2015-09-01 IST","2016-08-1 IST")))
[1] 3 3
请注意,quarters
是以"Q“开头的字符串,而lubridate::quarter
是一个整数。
https://stackoverflow.com/questions/52760802
复制