Learn R Programming

prospectr (version 0.2.0)

binning: Signal binning

Description

Compute average values of a signal in pre-determined bins (col-wise subsets). The bin size can be determined either directly or by specifying the number of bins. Sometimes called boxcar transformation in signal processing

Usage

binning(X, bins, bin.size)

Arguments

X

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

bins

the number of bins.

bin.size

the desired size of the bins.

Value

a matrix or vector with average values per bin.

See Also

savitzkyGolay, movav, gapDer, continuumRemoval

Examples

Run this code
# NOT RUN {
data(NIRsoil)
# conversion to reflectance
spc <- 1/10^NIRsoil$spc 
wav <- as.numeric(colnames(spc))

# 5 first spectra
matplot(wav, t(spc[1:5,]), 
        type = 'l', 
        xlab = 'Wavelength /nm', 
        ylab = 'Reflectance') 
binned <- binning(spc, bin.size = 20)

# bin means
matpoints(as.numeric(colnames(binned)), t(binned[1:5,]), pch = 1:5) 

binned <- binning(spc, bins = 20)
dim(binned) # 20 bins

# 5 first spectra
matplot(wav, t(spc[1:5,]), 
        type = 'l', 
        xlab = 'Wavelength /nm', 
        ylab = 'Reflectance') 
# bin means
matpoints(as.numeric(colnames(binned)), 
          t(binned[1:5,]), pch = 1:5) 
# }

Run the code above in your browser using DataLab