文章目录
函数介绍
r
复制代码
rollmean(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
rollmax(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
rollmedian(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
rollsum(x, k, fill = if (na.pad) NA, na.pad = FALSE,
align = c("center", "left", "right"), ...)
rollmeanr(..., align = "right")
rollmaxr(..., align = "right")
rollmedianr(..., align = "right")
rollsumr(..., align = "right")
- x: 是一个序列。
- k: 滑动窗口的宽度,对于rollmedian函数必须是个奇数。
- fill: 是一个三个元素的向量或者是一个list, 提供在数据左边/中间/右边的填充数据。
- na.pad: 不建议使用的命令。用fill=NA来代替na.pad=TRUE
- align: 接受一个字符串(left, center, right)来确定结果是左边滚动、右边滚动或者是中间滚动。
- rollxxxr:表示align='right'的情形
- 默认情况下align='center'
rollmean()
r
复制代码
x=1:10
rollmean(x,k=3,fill = c(-1,-2,-3),align = 'left')
# [1] 2 3 4 5 6 7 8 9 -3 -3
rollmean(x,k=3,fill = c(-1,-2,-3),align = 'center')
# [1] -1 2 3 4 5 6 7 8 9 -3
rollmean(x,k=3,fill = c(-1,-2,-3),align = 'right')
[1] -1 -1 2 3 4 5 6 7 8 9
rollmax()
r
复制代码
x=1:10
rollmax(x,k=3,fill = c(-1,-2,-3),align = 'left')
# [1] 3 4 5 6 7 8 9 10 -3 -3
rollmax(x,k=3,fill = c(-1,-2,-3),align = 'center')
# [1] -1 3 4 5 6 7 8 9 10 -3
rollmax(x,k=3,fill = c(-1,-2,-3),align = 'right')
# [1] -1 -1 3 4 5 6 7 8 9 10
r
复制代码
x=1:10
rollmedian(x,k=3,fill = c(-1,-2,-3),align = 'left')
# [1] 3 4 5 6 7 8 9 10 -3 -3
rollmedian(x,k=3,fill = c(-1,-2,-3),align = 'center')
# [1] -1 2 3 4 5 6 7 8 9 -3
rollmedian(x,k=3,fill = c(-1,-2,-3),align = 'right')
# [1] -1 -1 2 3 4 5 6 7 8 9
rollsum
r
复制代码
x=1:10
rollsum(x,k=3,fill = c(-1,-2,-3),align = 'left')
# [1] 6 9 12 15 18 21 24 27 -3 -3
rollsum(x,k=3,fill = c(-1,-2,-3),align = 'center')
# [1] -1 6 9 12 15 18 21 24 27 -3
rollsum(x,k=3,fill = c(-1,-2,-3),align = 'right')
# [1] -1 -1 6 9 12 15 18 21 24 27