Calculate summary statistic spectra in hyperSpec object for all spectra and by levels of factor variable by.

spStat(sp, by, FUN = mean, Name_of.by = as.character(match.call()$by), ...)

Arguments

sp

A hyperSpec object.

by

A grouping variable (either variable name of sp, or vector (factor) of length length(sp)

FUN

A function to apply.

Name_of.by

(Do not change this!) The name of input by.

...further

arguments passed to FUN.

Value

A hyperSpec object that contains summary statistic. Additional column .aggregate is added. In this column levels of grouping variable are indicated.

Note

This function is similar to aggregate, just calculates additional statistic for all spectra. This statistic is labeled by adding level .ALL) in variable .aggregate and variable, that has the same name as by (if Name_of.by si not modified).

Author

Vilmantas Gegzna

Examples

spStat(Spectra2, gr)
#> Error in getVarValues(VAR = by, DATA = sp): object 'gr' not found
spStat(Spectra2, by = gr,          FUN = IQR)
#> Error in getVarValues(VAR = by, DATA = sp): object 'gr' not found

## BUG:
# spStat(Spectra2, by = Spectra2$gr, FUN = IQR)