The spectra from all objects will be put into one object. The resulting object has all wavelengths that occur in any of the input objects, wl.tolerance is used to determine which difference in the wavelengths is tolerated as equal: clusters of approximately equal wavelengths will span at most 2 * wl.tolerance. Differences up to +/- wl.tolerance are considered equal.

The returned object has wavelengths that are the weighted average (by number of spectra) of the wavelengths within any such cluster of approximately equal wavelengths.

Labels will be taken from the first object where they are encountered. However, the order of processing objects is not necessarily the same as the order of objects in the input: collapse first processes groups of input objects that share all wavelengths (within wl.tolerance).

Data points corresponding to wavelengths not in the original spectrum will be set to NA. Extra data is combined in the same manner.

If the objects are named, the names will be preserved in extra data column $.name. If the wavelengths are names, names are preserved and taken from the first object where they were encountered, the same applies to possible column names of the spectra matrix.

collapse(
  ...,
  wl.tolerance = hy_get_option("wl.tolerance"),
  collapse.equal = TRUE
)

Arguments

...

hyperSpec objects to be collapsed into one object. Instead of giving several arguments, a list with all objects to be collapsed may be given.

wl.tolerance

Tolerance to decide which wavelengths are considered equal.

collapse.equal

Logical indicating whether to try first finding groups of spectra with (approximately) equal wavelength axes. If the data is known to contain few or no such groups, collapse() will be faster with this first pass being turned off.

Value

A hyperSpec object

Author

C. Beleites

Examples

barbiturates[1:3]
#> [[1]]
#> hyperSpec object
#>    1 spectra
#>    4 data columns
#>    37 data points / spectrum
#> 
#> [[2]]
#> hyperSpec object
#>    1 spectra
#>    4 data columns
#>    34 data points / spectrum
#> 
#> [[3]]
#> hyperSpec object
#>    1 spectra
#>    4 data columns
#>    29 data points / spectrum
#> 
collapse(barbiturates[1:3])
#> hyperSpec object
#>    3 spectra
#>    4 data columns
#>    57 data points / spectrum

a <- barbiturates[[1]]
b <- barbiturates[[2]]
c <- barbiturates[[3]]

a
#> hyperSpec object
#>    1 spectra
#>    4 data columns
#>    37 data points / spectrum

b
#> hyperSpec object
#>    1 spectra
#>    4 data columns
#>    34 data points / spectrum

c
#> hyperSpec object
#>    1 spectra
#>    4 data columns
#>    29 data points / spectrum

collapse(a, b, c)
#> hyperSpec object
#>    3 spectra
#>    4 data columns
#>    57 data points / spectrum

collapse(barbiturates[1:3], collapse.equal = FALSE)
#> hyperSpec object
#>    3 spectra
#>    4 data columns
#>    57 data points / spectrum