movavg: Return a moving average of the 2D dataset in question

View source: R/movavg.R

movavgR Documentation

Return a moving average of the 2D dataset in question

Description

The function returns a 2 column data frame with the first column named X. The second column named Y contains the averaged dataset

Usage

movavg(X,Y,bn,fn)

Arguments

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

Author(s)

Chitran Ghosal

Examples

###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))

Chitran1987/StatsChitran documentation built on Feb. 23, 2025, 8:30 p.m.