Functions to bind hyperSpec objects.
cbind2 binds the spectral matrices of two hyperSpec objects
by column. All columns besides spc with the same name in x@data and
y@data must have the same elements. Rows are ordered before checking.
bind( direction = stop("direction('c' or 'r') required"), ..., wl.tolerance = hy.getOption("wl.tolerance") ) # S3 method for hyperSpec cbind(...) # S3 method for hyperSpec rbind(...) # S4 method for hyperSpec,hyperSpec cbind2(x, y) # S4 method for hyperSpec,missing cbind2(x, y) # S4 method for hyperSpec,hyperSpec rbind2(x, y, wl.tolerance = hy.getOption("wl.tolerance")) # S4 method for hyperSpec,missing rbind2(x, y, wl.tolerance)
| direction | "r" or "c" to bind rows or columns |
|---|---|
| ... | The Alternatively, one list of |
| wl.tolerance |
|
| x, y |
|
a hyperSpec object, possibly with different row order (for
bind ("c", ...{}) and cbind2).
The former difficulties with binding S4 objects are resolved since R version
3.2.0 and cbind() and rbind() now work as intended and expected for
hyperSpec objects.
Therefore, calling rbind.hyperSpec and cbind.hyperSpec is now depecated:
cbind and rbind should now be called directly.
However, in consequence it is no longer possible to call cbind() or rbind()
with a list of hyperSpec objects. In that case, use bind() or
base::do.call() (see example).
bind() does the common work for both column- and row-wise binding.
You might have to make sure that the objects either all have or all do not have rownames and/or colnames.
methods::rbind2(), methods::cbind2()
base::rbind(), base::cbind()
merge() and collapse() for combining objects that do not share spectra
or wavelengths, respectively.
C. Beleites
faux_cell#> hyperSpec object #> 875 spectra #> 4 data columns #> 300 data points / spectrum #> wavelength: Delta * tilde(nu)/cm^-1 [numeric] 602 606 ... 1798 #> data: (875 rows x 4 columns) #> 1. x: x position [numeric] -11.55 -10.55 ... 22.45 #> 2. y: y position [numeric] -4.77 -4.77 ... 19.23 #> 3. region: [factor] matrix matrix ... matrix #> 4. spc: intensity (arbitrary units) [matrix, array300] 15 168 ... 93bind("r", faux_cell, faux_cell)#> hyperSpec object #> 1750 spectra #> 4 data columns #> 300 data points / spectrum #> wavelength: Delta * tilde(nu)/cm^-1 [numeric] 602 606 ... 1798 #> data: (1750 rows x 4 columns) #> 1. x: x position [numeric] -11.55 -10.55 ... 22.45 #> 2. y: y position [numeric] -4.77 -4.77 ... 19.23 #> 3. region: [factor] matrix matrix ... matrix #> 4. spc: intensity (arbitrary units) [matrix, array300] 15 168 ... 93#> hyperSpec object #> 1750 spectra #> 4 data columns #> 300 data points / spectrum #> wavelength: Delta * tilde(nu)/cm^-1 [numeric] 602 606 ... 1798 #> data: (1750 rows x 4 columns) #> 1. x: x position [numeric] -11.55 -10.55 ... 22.45 #> 2. y: y position [numeric] -4.77 -4.77 ... 19.23 #> 3. region: [factor] matrix matrix ... matrix #> 4. spc: intensity (arbitrary units) [matrix, array300] 15 168 ... 93#> hyperSpec object #> 875 spectra #> 4 data columns #> 600 data points / spectrum #> wavelength: Delta * tilde(nu)/cm^-1 [numeric] 602 606 ... 1798 #> data: (875 rows x 4 columns) #> 1. x: x position [numeric] -11.55 -10.55 ... 22.45 #> 2. y: y position [numeric] -4.77 -4.77 ... 19.23 #> 3. region: [factor] matrix matrix ... matrix #> 4. spc: intensity (arbitrary units) [matrix, array600] 15 168 ... 93#> hyperSpec object #> 2625 spectra #> 4 data columns #> 300 data points / spectrum #> wavelength: Delta * tilde(nu)/cm^-1 [numeric] 602 606 ... 1798 #> data: (2625 rows x 4 columns) #> 1. x: x position [numeric] -11.55 -10.55 ... 22.45 #> 2. y: y position [numeric] -4.77 -4.77 ... 19.23 #> 3. region: [factor] matrix matrix ... matrix #> 4. spc: intensity (arbitrary units) [matrix, array300] 15 168 ... 93x <- faux_cell[, , 600:605] x$a <- 1 x@data <- x@data[, sample(ncol(x), ncol(x))] # reorder columns y <- faux_cell[nrow(faux_cell):1, , 1730:1750] # reorder rows y$b <- 2 cbind2(x, y) # works#> hyperSpec object #> 875 spectra #> 6 data columns #> 27 data points / spectrum #> wavelength: Delta * tilde(nu)/cm^-1 [numeric] NA NA ... 1750 + NA #> data: (875 rows x 6 columns) #> 1. spc: intensity (arbitrary units) [matrix, array27] NA NA ... 34 + NA #> 2. a: a [numeric] 1 1 ... 1 #> 3. x: x position [numeric] -11.55 -10.55 ... 22.45 #> 4. region: [factor] matrix matrix ... matrix #> 5. y: y position [numeric] -4.77 -4.77 ... 19.23 #> 6. b: [numeric] 2 2 ... 2#> hyperSpec object #> 875 spectra #> 6 data columns #> 27 data points / spectrum #> wavelength: Delta * tilde(nu)/cm^-1 [numeric] NA NA ... 1750 + NA #> data: (875 rows x 6 columns) #> 1. spc: intensity (arbitrary units) [matrix, array27] NA NA ... 34 + NA #> 2. a: a [numeric] 1 1 ... 1 #> 3. x: x position [numeric] -11.55 -10.55 ... 22.45 #> 4. region: [factor] matrix matrix ... matrix #> 5. y: y position [numeric] -4.77 -4.77 ... 19.23 #> 6. b: [numeric] 2 2 ... 2#> hyperSpec object #> 12 spectra #> 3 data columns #> 181 data points / spectrum #> wavelength: lambda/nm [numeric] 405.0 405.5 ... 495 #> data: (12 rows x 3 columns) #> 1. spc: I[fl]/"a.u." [matrix, array181] 27.15000 66.80133 ... 294.6495 #> 2. filename: filename [character] rawdata/flu1.txt rawdata/flu2.txt ... rawdata/flu6.txt #> 3. c: c / (mg / l) [numeric] 0.05 0.10 ... 0.3bind("r", lhy)#> hyperSpec object #> 12 spectra #> 3 data columns #> 181 data points / spectrum #> wavelength: lambda/nm [numeric] 405.0 405.5 ... 495 #> data: (12 rows x 3 columns) #> 1. spc: I[fl]/"a.u." [matrix, array181] 27.15000 66.80133 ... 294.6495 #> 2. filename: filename [character] rawdata/flu1.txt rawdata/flu2.txt ... rawdata/flu6.txt #> 3. c: c / (mg / l) [numeric] 0.05 0.10 ... 0.3