Learn R Programming

prospectr (version 0.1.3)

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
numeric data.frame, matrix or vector to process
w
filter length

Value

a matrix or vector with the filtered signal(s)

See Also

sgolayfilt, savitzkyGolay, gapDer, binning, continuumRemoval

Examples

Run this code
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