[.spectra | R Documentation |
`[`
Subsets spectra by sample names (rows) or (and) bands (columns)
## S3 method for class 'spectra' x[i, j, simplify = TRUE]
x |
spectra object |
i |
Sample names (preferred), index, or a logical vector of length nrow(x) |
j |
band labels, as numeric or character or a logical vector of length ncol(x). Do not use indexes! |
simplify |
Boolean. If TRUE (default), single band selections are returned as a named vector of values |
Subset operations based on samples (first argument) will match sample names or indexes, in that order. The spectra constructor ensures that names are not numeric nor are coercible to numeric, such that x[1:2, ] will return the first and second samples in the 'spectra' object. Subsetting based on bands (second argument) matches the band labels, not indices! That is, x[ , 600] will give you the value data for the 600nm band and not the 600th band. Boolean vectors of the appropriate length can be used to subset samples and bands.
usually a spectra object, but see param 'simplify'
Jose Eduardo Meireles
library(spectrolab) spec = as_spectra(spec_matrix_example, name_idx = 1) head(names(spec), n = 3) # by name spec1 = spec[ "species_7" , ] spec1 # by band spec2 = spec[ , 400:700 ] spec2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.