我不确定我是否做错了什么,但是我注意到,如果我尝试使用dplyr汇总包含持续时间数据的数据,则返回的单位不一致/不正确。为什么总结得出错误的单位?
library(lubridate)
time1 <- as.POSIXct("2018-06-27 12:08 AM")
time2 <- as.POSIXct("2018-02-15 16:33:58")
a <- data.frame(
time = time1 + 1:3600 * 60
)
b <- data.frame(
time = time2 + 1:3600 * 3600
)
c <- bind_rows(a,b,.id = "group")
# Units are incorrect
c %>%
group_by(group) %>%
summarise(
median(diff(time))
)
# They should look more like this
aggregate(time ~ group,data = c,FUN = function(x) median(diff(x)))
aggregate(time ~ group,FUN = function(x) units(median(diff(x))))