Applies a twosided moving median window on a vector, where the window paramter is the total size of the window. The value in the window middle is the index where the median of the window is written. Therefore the window size has to be an uneven number. The border region of the vetor is filled with a one-sided median. There might be border effects.

movingMedian(data, window)

Arguments

data

numeric vector

window

uneven number for the size of the moving window

Value

A numeric vector.

Examples

movingMedian(sequence(1:10), window = 5)
#>  [1] 1 1 1 2 2 2 2 3 2 2 3 3 3 3 3 3 3 3 4 4 4 3 3 3 4 5 5 5 3 3 3 4 5 6 6 6 3 3
#> [39] 3 4 5 6 7 7 7 3 3 3 4 5 6 7 9 9 9