Learn R Programming

spectrolab (version 0.0.18)

apply_by_band: 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 spectra apply_by_band(x, fun, na.rm = TRUE, keep_txt_meta = TRUE, name = NULL, ...)

Value

spectra

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

Methods (by class)

  • apply_by_band(spectra): Apply a numeric function by band

Author

Jose Eduardo Meireles

Examples

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

Run the code above in your browser using DataLab