movavg | R Documentation |
The function returns a 2 column data frame with the first column named X. The second column named Y contains the averaged dataset
movavg(X,Y,bn,fn)
X |
The X vector of the 2D dataset |
Y |
The Y vector of the 2D dataset |
bn |
The no. of elements before the current element thatyou want included in the average |
fn |
The no. of elements after the current element(future element) thatyou want included in the average |
Chitran Ghosal
###plotting a noisy parabola
x <- seq(-1, 1, by = 0.01)
y <- x^2 + rnorm(length(x), mean=0, sd=0.1)
plot(x,y)
###plotting the moving average
df <- movavg(x,y, 10, 10) #moving average of bn = fn = 10
lines(df$X, df$Y, col='red')
df <- movavg(x, y, 1, 10) ##moving average of bn = 1 and fn = 10
lines(df$X, df$Y, col = 'blue')
legend('top', legend = c('Noisy Data', 'movavg(bn = fn = 10)', 'movavg(bn = 1, fn = 10)'), col = c('black', 'red', 'blue'), lty = c(1,1,1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.