sma | R Documentation |
Smoothes a series by means of a windowed mean. If x is an input series and y is the output filtered series, then:
y[i] = mean(x[(i-window_size+1) : i])
sma(x, window_size, recentre = TRUE, miss = "single")
x |
Input time-series as a vector. |
window_size |
Window size as an integer |
recentre |
Whether to recentre the window around the middle point in the window so as to avoid adding lag. I.e. for an odd window_length y[i] = mean(x[(i - floor(window_length/2)) : (i + floor(window_length/2))]) For an even window length the output is located more closely to earlier points, i.e. y[i] = mean(x[(i - window_length/2 + 1) : (i + window_length/2)]) |
miss |
How to handle missing values. 'single' only returns NA for y[i] if x[i] = NA. 'all' returns NA for y[i] if any value in the window is missing, and 'none' omits NAs from the window, so will only return NA for y[i] if all windowed values are also NA. |
A filtered time-series the same length as x.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.