Learn R Programming

rchemo (version 0.1-3)

mavg: Smoothing by moving average

Description

Smoothing, by moving average, of the row observations (e.g. spectra) of a dataset.

Usage

mavg(X, n = 5)

Value

A matrix of the transformed data.

Arguments

X

X-data (\(n, p\)).

n

The number of points (i.e. columns of X) defining the window over wich is calculate each average. The smoothing is calculated for the point at the center of the window. Therefore, n must be an odd integer, and be higher or equal to 3.

Examples

Run this code

data(cassav)

X <- cassav$Xtest
headm(X)

Xp <- mavg(X, n = 11)
headm(Xp)

oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(1, 2))
plotsp(X, main = "Signal")
plotsp(Xp, main = "Corrected signal")
abline(h = 0, lty = 2, col = "grey")
par(oldpar)

Run the code above in your browser using DataLab