extract: Extracting and replacing parts of Spectra* objects

Description Value Methods Author(s) See Also Examples

Description

These methods emulates classic base methods '[', '[[' and '$' to extract or replace parts of Spectra* objects.

Value

These methods either return an object of the same clss as x, or can promote a Spectra object to a SpectraDataFrame object by adding data ("[[<-" and "$<-" methods).

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

Author(s)

Pierre Roudier pierre.roudier@gmail.com

See Also

subset, aggregate_spectra

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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))
summary(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)
summary(australia)

# Promote Spectra to SpectraDataFrame
s <- as(australia, 'Spectra')
class(s)
s$foo <- runif(nrow(s))
summary(s)

inspectr documentation built on May 2, 2019, 5:45 p.m.