extraction-methods | R Documentation |
These methods emulates classic base methods '[', '[[' and '$' to extract or replace parts of Spectra* objects.
\S4method{[}{Spectra}(x,i,j,...,drop=FALSE)
\S4method{[[}{Spectra}(x,i,j,...)
\S4method{$}{SpectraDataFrame}(x,name)
\S4method{$}{Spectra}(x,name) <- value
\S4method{[[}{Spectra}(x,i,j,...) <- value
x |
an object of class |
i, j, ... |
indices specifying elements to extract or replace |
drop |
currently ignored |
name |
A literal character string or a name (possibly backtick quoted) |
value |
typically an array-like R object of a similar class as x |
These methods either return an object of the same class as x
,
or can promote a Spectra
object to a SpectraDataFrame
object
by adding data ("[[<-" and "$<-" methods).
x=Spectra
x[i, j, ..., drop = FALSE]
x$name <- value
x[[name]] <- value
x | A Spectra object |
|
i
| Row index of the selected individuals | |
j | Selected wavelengths | |
name | A literal character string or a name | |
... | Ignored | |
drop | Ignored | |
x=SpectraDataFrame
x[i, j, k, ..., drop = FALSE]
x[[name]]
x[[name]] <- value
x$name
x$name <- value
x | A SpectraDataFrame object |
|
i | Row index of the selected individuals | |
j | Selected wavelengths | |
k | Selected columns in the @data slot | |
name | A literal character string or a name | |
... | Ignored | |
drop | Ignored | |
Pierre Roudier pierre.roudier@gmail.com
# Loading example data
data(australia)
spectra(australia) <- sr_no ~ ... ~ 350:2500
# Getting features information from SpectraDataFrame
australia$carbon
australia[['carbon']]
# Creating new features
australia$foo <- runif(nrow(australia))
australia[['bar']] <- runif(nrow(australia))
# Replacing values
australia$foo <- sample(
LETTERS[1:5],
size = nrow(australia),
replace = TRUE
)
australia[['bar']] <- sample(
c(TRUE, FALSE),
size = nrow(australia),
replace = TRUE
)
# Promote Spectra to SpectraDataFrame
s <- as(australia, 'Spectra')
class(s)
s$foo <- runif(nrow(s))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.