Learn R Programming

hyperSpec (version 0.100.2)

apply: apply Computes summary statistics for the spectra of a hyperSpec object.

Description

apply gives the functionality of apply for hyperSpec objects.

Usage

# S4 method for hyperSpec
apply(
  X,
  MARGIN,
  FUN,
  ...,
  label.wl = NULL,
  label.spc = NULL,
  new.wavelength = NULL,
  simplify
)

Value

A hyperSpec object

Arguments

X, spc

a hyperSpec object

MARGIN

The subscript which the function will be applied over.

1 indicates rows (FUN is applied to each spectrum),

2 indicates columns (FUN is applied to each wavelength),

1 : 2 indicates that FUN should be applied to each single element of the spectra matrix. Note that many basic mathematical functions are already defined for hyperSpec objects (see Math).

If MARGIN is missing, the whole spectra matrix is handed to FUN, see also the examples.

FUN

function to compute the summary statistics

...

further arguments passed to FUN

label.wl, label.spc

new labels for wavelength and spectral intensity axes

new.wavelength

for MARGIN = 2: numeric vector or name of the argument in ... that is to be used (character) as wavelength axis of the resulting object.

simplify

ignored: apply for hyperSpec results are always simplified

Author

C. Beleites

Details

The generic functions of group Math are not definded for hyperSpec objects. Instead, apply can be used. For functions like log that work on scalars, MARGIN = 1 : 2 gives the appropriate behaviour.

spcapply does the same as apply with MARGIN = 1, but additionally allows to set a new wavelength axis and adjust the labels.

wlapply does the same as apply with MARGIN = 2, but additionally allows to set a new wavelength axis and adjust the labels.

See Also

apply, for applying FUN to subgroups of the hyperSpec object: aggregate.

Examples

Run this code


plotspc (apply (chondro, 2, range))

avgflu <- apply (flu, 1, mean,
                 label.spc = expression (bar (I)),
                 new.wavelength = mean (wl (flu)))
avgflu

flu[[,,405:407]]
apply (flu, 1:2, "*", -1)[[,,405:407]]

## without MARGIN the whole matrix is handed to FUN
apply (flu [,,405:407], , print) [[]]

## whereas MARGIN = 1 : 2 leads to FUN being called for each element separately
apply (flu [,,405:407], 1 : 2, print) [[]]

Run the code above in your browser using DataLab