apply_by_band {spectrolab}R Documentation

Apply numeric function by band

Description

apply_by_band is conceptually similar to apply(as.matrix(x), 2, fun), but returns a spectra object while dealing with metadata and attributes. Applying a function that does not act on numeric values may crash the function or render all values NA.

Usage

apply_by_band(x, fun, na.rm = TRUE, keep_txt_meta = TRUE, name = NULL, ...)

## S3 method for class 'spectra'
apply_by_band(x, fun, na.rm = TRUE, keep_txt_meta = TRUE, name = NULL, ...)

Arguments

x

spectra

fun

numeric function to be applied to each band.

na.rm

boolean. remove NAs?

keep_txt_meta

boolean. try to keep text in the metadata?

name

name for each sample in the output spectra. The default (NULL) will give samples sequential numeric names. Recycled if necessary.

...

extra arguments passed to fun

Value

spectra

Methods (by class)

Author(s)

Jose Eduardo Meireles

Examples

library(spectrolab)
spec = as_spectra(spec_matrix_example, name_idx = 1)
spec_mean = apply_by_band(spec, mean)

[Package spectrolab version 0.0.19 Index]