aggregate.spectra: Aggregate spectra

View source: R/transform_spectra.R

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

spectrolab documentation built on Feb. 16, 2023, 10:27 p.m.