extraction-methods: Extracting and replacing parts of Spectra* objects

Description Usage Arguments Value Methods Author(s) Examples

Description

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

Usage

1
2
3
4
5
\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

Arguments

x

an object of class Spectra or SpectraDataFrame

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

Value

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).

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

Examples

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

spectacles documentation built on Jan. 13, 2021, 8:46 a.m.