2022-9: An Average Window (or a Windowed Average)
Write code that:
- takes a second argument Y that is a numeric scalar or non-empty vector.
- takes a first argument X that represents the number of neighboring elements on either side of each element in Y.
- returns a numeric vector or scalar where each element is the average (mean) of the corresponding element in Y and its X neighbors on either side. If an element has fewer than X neighbors on either side, replicate the first and last values as necessary to make X neighbors.
Examples
Implementation
You can also run the tests via ⌘/shift + enter