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

extraction-methodsR Documentation

Extracting and replacing parts of Spectra* objects

Description

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

Usage

\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


# 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 July 10, 2023, 1:59 a.m.