Fast rolling range with aligment using C++/Rcpp.
Additional performance gains can be achieved by skipping increment values between calculations.
roll_range(x, n = 7, increment = 1, align = "center")A vector of rolling values that difference the maximum and minimum values, of the same length as x.
an R numeric vector
integer window size
integer shift to use when sliding the window to the next location
window alignment, one of "left"|"center"|"right"
The window size n is interpreted as the full window length.
Setting increment to a value greater than one will result in NAs for all skipped-over indices.
The align parameter determines the alignment of the current index within the window. Thus:
align="left" [*------] will cause the returned vector to have n-1 NA values at the right end.
align="center" [---*---] will cause the returned vector to have (n-1)/2 NA values at either end.
align="right" [------*] will cause the returned vector to have n-1 NA values at the left end.