cumsumWindow | R Documentation |
Calculate the cumulative sum of a set of numbers within a vector. The
difference between this and cumsum()
is that it is a
sliding window approach, so sums are not necessarily calculated over the
entire length of the vector. When cut == length(x)
then it is the
same as cumsum()
. Also, for entries <
window, i.e.
the beginning, the entries returned will be identical to cumsum()
.
cumsumWindow(x, window)
x |
The vector to be summed across. |
window |
The length/size of the window to sum within (the moving cutoff). |
If window >= length(x)
, a warning is triggered and
cumsumWindow
reverts to cumsum()
.
A vector of the sums of the sliding window for the cumulative sums.
Stu Field
cumsum()
cumsumWindow(1:20, 5) cumsumWindow(1:20, window = 20) cumsum(1:20) r.vec <- sample(1:20, 100, replace=TRUE) # random vector cumsumWindow(r.vec, 5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.