LaT*_*Fan 1 r vector cumsum rollapply
这是继前一个问题一个.在该问题中,建议用于rollapply计算1st, 2nd, 3rd向量条目的总和; 然后2nd, 3rd, 4th,等等.
rollapply
1st, 2nd, 3rd
2nd, 3rd, 4th
我的问题是如何计算总和1st, 2nd and 3rd; 那么4th, 5th and 6th.也就是说,滚动没有重叠.这可以轻松完成吗?
1st, 2nd and 3rd
4th, 5th and 6th
Sot*_*tos 6
同样的想法.您只需要指定by参数.默认值为1.
x <-c(1, 5, 4, 5, 7, 8, 9, 2, 1) zoo::rollapply(x, 3, by = 3, sum) #[1] 10 20 12 #or another Base R option sapply(split(x, ceiling(seq_along(x)/3)), sum) # 1 2 3 #10 20 12
归档时间:
9 年,3 月 前
查看次数:
748 次
最近记录: