R 中“difftime”对象的“cumsum”等价函数是什么?
sectionDuration 是一个 difftime 对象
cumSectionDuration = cumsum(sectionDuration)
报错
最佳答案
请考虑使用Reduce
函数。
您不会像 as.numeric
解决方案中那样丢失类型。
a <- difftime(Sys.time(), Sys.time())
b <- difftime(Sys.time(), Sys.time())
# ERROR cumsum(c(a, b))
# 'cumsum' not defined for "difftime" objects
Reduce("+", c(a, b))
#> Time difference of -9.059906e-06 secs
创建于 2023-03-09 reprex v2.0.2
关于r - R 中 'cumsum' 对象的 "difftime"的等效函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75689454/