Learn R Programming

prospectr (version 0.2.0)

movav: Moving average

Description

A simple moving average of a vector, data.frame or matrix using a convolution function written in C++/Rcpp for fast computing

Usage

movav(X, w)

Arguments

X

a numeric data.frame, matrix or vector to process.

w

filter length.

Value

a matrix or vector with the filtered signal(s)

See Also

savitzkyGolay, gapDer, binning, continuumRemoval

Examples

Run this code
# NOT RUN {
data(NIRsoil)
wav <- as.numeric(colnames(NIRsoil$spc))
spc <- 1/10^NIRsoil$spc # conversion to reflectance
spc <- spc + rnorm(length(spc), 0, 0.001) # adding some noise
matplot(wav, t(spc[1:10, ]), type = 'l', xlab = 'Wavelength /nm', ylab = 'Reflectance')
mov <- movav(spc, w = 11) # window size of 11 bands
matlines(as.numeric(colnames(mov)), t(mov[1:10, ])) # smoothed data
# }

Run the code above in your browser using DataLab