Learn R Programming

spectrolab (version 0.0.18)

aggregate.spectra: Aggregate spectra

Description

Applies FUN (and FUN_meta) over spectra aggregating by factor `by`.

Usage

# S3 method for spectra
aggregate(x, by, FUN, FUN_meta = NULL, ...)

Value

spectra object

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

Author

Jose Eduardo Meireles

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).

Examples

Run this code
library(spectrolab)
spec = as_spectra(spec_matrix_example, name_idx = 1)
spec_mean = aggregate(spec, by = names(spec), mean, try_keep_txt(mean))

Run the code above in your browser using DataLab