binning | R Documentation |
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
binning(X, bins, bin.size)
X |
a numeric matrix or vector to process (optionally a data frame that can be coerced to a numerical matrix). |
bins |
the number of bins. |
bin.size |
the desired size of the bins. |
a matrix or vector with average values per bin.
Antoine Stevens & Leonardo Ramirez-Lopez
savitzkyGolay
, movav
,
gapDer
, continuumRemoval
data(NIRsoil)
wav <- as.numeric(colnames(NIRsoil$spc))
# 5 first spectra
matplot(wav, t(NIRsoil$spc[1:5, ]),
type = "l",
xlab = "Wavelength /nm",
ylab = "Absorbance"
)
NIRsoil$spc_binned <- binning(NIRsoil$spc, bin.size = 20)
# bin means
matpoints(as.numeric(colnames(NIRsoil$spc_binned)),
t(NIRsoil$spc_binned[1:5, ]),
pch = 1:5
)
NIRsoil$spc_binned <- binning(NIRsoil$spc, bins = 20)
dim(NIRsoil$spc_binned) # 20 bins
# 5 first spectra
matplot(wav,
t(NIRsoil$spc[1:5, ]),
type = "l",
xlab = "Wavelength /nm",
ylab = "Absorbance"
)
# bin means
matpoints(as.numeric(colnames(NIRsoil$spc_binned)),
t(NIRsoil$spc_binned[1:5, ]),
pch = 1:5
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.