Description Usage Arguments Examples
'rollingSum' is a commodity function invoking 'zoo::rollapply' with 'FUN=sum'.
'rollapply.delftfews' overrides 'rollapply.zoo' defaults for 'na.pad' (set to TRUE) and ‘align' (set to ’right'). this can also be done by changing global settings at the moment you load the library.
1 |
data |
the input data vector with instantaneous values |
width |
the number of values of the sum. |
na.action |
what to do with NA values. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | # on this input
input <- c(rep(1:3, 2), NA)
# [1] 1 2 3 1 2 3 NA
# this sums the two elements [i-1, i]
rollingSum(input, 2)
# [1] NA 3 5 4 3 5 3
# the three elements [i-2, i-1, i]
rollingSum(input, 3)
# [1] NA NA 6 6 6 6 5
rollingSum(input, 4)
# notice how the first `width - 1` elements in the result are NA
# [1] NA NA NA 7 8 9 6
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.