aggregate.spectra {spectrolab} | R Documentation |
Aggregate spectra
Description
Applies FUN (and FUN_meta) over spectra aggregating by factor 'by'.
Usage
## S3 method for class 'spectra'
aggregate(x, by, FUN, FUN_meta = NULL, ...)
Arguments
x |
spectra object |
by |
vector of factors to guide the aggregation |
FUN |
function to be applied to value (and meta if FUN_meta is NULL) |
FUN_meta |
function to be applied to metadata. If NULL (default), same FUN applied to value is used. |
... |
extra args to FUN |
Details
Argument FUN_meta is useful if you want to apply a different function to
metadata and value. If you want to aggregate spectra and metadata
using 'mean', 'sd', 'median' etc. but try to keep the text values, wrap your
function in try_keep_txt(f)
.
Value
spectra object
Author(s)
Jose Eduardo Meireles
Examples
library(spectrolab)
spec = as_spectra(spec_matrix_example, name_idx = 1)
spec_mean = aggregate(spec, by = names(spec), mean, try_keep_txt(mean))
[Package spectrolab version 0.0.19 Index]