函数介绍
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()
x=1:10
rollmean(x,k=3,fill = c(-1,-2,-3),align = 'left')
rollmean(x,k=3,fill = c(-1,-2,-3),align = 'center')
rollmean(x,k=3,fill = c(-1,-2,-3),align = 'right')
[1] -1 -1 2 3 4 5 6 7 8 9
rollmax()
x=1:10
rollmax(x,k=3,fill = c(-1,-2,-3),align = 'left')
rollmax(x,k=3,fill = c(-1,-2,-3),align = 'center')
rollmax(x,k=3,fill = c(-1,-2,-3),align = 'right')
rollmedian
x=1:10
rollmedian(x,k=3,fill = c(-1,-2,-3),align = 'left')
rollmedian(x,k=3,fill = c(-1,-2,-3),align = 'center')
rollmedian(x,k=3,fill = c(-1,-2,-3),align = 'right')
rollsum
x=1:10
rollsum(x,k=3,fill = c(-1,-2,-3),align = 'left')
rollsum(x,k=3,fill = c(-1,-2,-3),align = 'center')
rollsum(x,k=3,fill = c(-1,-2,-3),align = 'right')