我想创建一个像这样的时间间隔(0,5]月和(5,10]月。然后将这些时间间隔合并到(0,10]月。我用下面的数据框简化了我的真实的问题。
df <- data.frame(age = c(lubridate::period(c(0,1,0),c("day","month","year")),
lubridate::period(c(0,2,0),c("day","month","year")),
lubridate::period(c(0,3,0),c("day","month","year")),
lubridate::period(c(0,4,0),c("day","month","year")),
lubridate::period(c(0,5,0),c("day","month","year")),
lubridate::period(c(0,6,0),c("day","month","year")),
lubridate::period(c(0,7,0),c("day","month","year")),
lubridate::period(c(0,8,0),c("day","month","year")),
lubridate::period(c(0,9,0),c("day","month","year")),
lubridate::period(c(0,10,0),c("day","month","year"))
))
cut(df$age,breaks = c(
lubridate::period(c(0,0,0),c("day","month","year")),
lubridate::period(c(0,5,0),c("day","month","year")),
lubridate::period(c(0,10,0),c("day","month","year"))
))
截函数返回区间
我该怎么办?
1条答案
按热度按时间v8wbuo2f1#
您可以考虑底层的数字格式。