Apply a moving-window Hampel function to a numeric vector.
roll_hampel( x, width = 1L, by = 1L, align = c("center", "left", "right"), na.rm = FALSE )
Integer width of the rolling window.
Integer shift to use when sliding the window to the next location
Character position of the return value within the window. One of:
Logical specifying whether
Numeric vector of the same length as
The Hampel filter is a robust outlier detector using Median Absolute Deviation (MAD).
For every index in the incoming vector
x, a value is returned that
is the Hampel funcion of all values in
x that fall within a window of width
align parameter determines the alignment of the return value
within the window. Thus:
align = -1 [*------] will cause the returned vector to have width-1
NA values at the right end.
align = 0 [---*---] will cause the returned vector to have width/2
NA values at either end.
align = 1 [------*] will cause the returned vector to have width-1
NA values at the left end.
For large vectors, the
by parameter can be used to force the window
to jump ahead
by indices for the next calculation. Indices that are
skipped over will be assigned
NA values so that the return vector still has
the same length as the incoming vector. This can dramatically speed up
calculations for high resolution time series data.
#>  NA NaN NaN NaN NaN NaN NaN #>  0.0000000 0.0000000 0.6744908 NaN NaN NA