Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

mutate

Mutate a Spectra* object by transforming the spectra values, and/or adding new or replacing existing attributes.


Description

This function is very similar to transform but it executes the transformations iteratively so that later transformations can use the columns created by earlier transformations. Like transform, unnamed components are silently dropped.

Either the spectra, and/or the attributes (if the .data inherits from the SpectraDataFrame class) can be affected:

  • To affect the spectra, one should use the nir placeholder, eg nir = log(1/nir)

  • To affect the attributes of the object, the definitions of new columns are simply given using attributes names, newAttribute = 1/sqrt(attribute)

  • Both spectra and attrbutes can be transformed in one command.

Usage

## S4 method for signature 'Spectra'
mutate(.data, ...)

Arguments

.data

an object inheriting from the Spectra class

...

named parameters giving definitions of new columns

Author(s)

Pierre Roudier pierre.roudier@gmail.com, from code from Hadley Wickham

References

Hadley Wickham (2011). The Split-Apply-Combine Strategy for Data Analysis. Journal of Statistical Software, 40(1), 1-29. URL http://www.jstatsoft.org/v40/i01/.

Examples

# Loading example data
data(australia)
spectra(australia) <- sr_no ~ ... ~ 350:2500

# Modifying spectra
m <- mutate(australia, nir = log1p(1/nir))
plot(m)

# Modifying and creating attributes
m <- mutate(
  australia, 
  sqrt_carbon = sqrt(carbon), 
  foo = clay + ph, 
  nir = log1p(1/nir)
)
plot(m)

spectacles

Storing, Manipulating and Analysis Spectroscopy and Associated Data

v0.5-3
GPL-3
Authors
Pierre Roudier [aut, cre], Max Kuhn [ctb], Kristian Hovde Liland [ctb], Bjorn-Helge Mevik [ctb], Hadley Wickham [ctb], Raphael Viscarra Rossel [dtc]
Initial release
2021-01-11

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.