mavg: Smoothing by moving average

View source: R/mavg.R

mavgR Documentation

Smoothing by moving average

Description

Smoothing, by moving average, of the row observations (usually spectra) of a data set.

Usage

mavg(X, n = 3)

Arguments

X

A n x p matrix or data frame (usually spectra) on which are calculated the moving averages.

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.

Value

A matrix.

Examples


data(datcass)

X <- datcass$Xu

n <- 11
zX <- mavg(X, n) 

headm(X)
headm(zX)

oldpar <- par(mfrow = c(1, 1))
par(mfrow = c(1, 2))
plotsp(X, main = "Signal")
plotsp(zX, main = "Corrected signal")
par(oldpar)


mlesnoff/rnirs documentation built on April 24, 2023, 4:17 a.m.