spectacles (version 0.5-4)

ids: Retrieves or sets the ids of a Spectra* object.

Description

Either retrieves the wavelengths from a Spectra* object, or creates a Spectra* object from a "data.frame" object by setting some of its columns as the wavelengths. The "ids<-" method for SpectraDataFrame objects allows to use a formula interface to use a column in its data slot as the object IDs (see the last example provided in the Examples section).

Usage

ids(object, ...)
ids(object) <- value

# S4 method for Spectra ids(object) <- value

# S4 method for SpectraDataFrame ids(object) <- value

Value

The ids methods return a vector if as.vector is TRUE, a data.frame otherwise. The "ids<-" method return a SpectraDataFrame object (or a Spectra object if the column in the data slot that has been used to initiate the IDs was the only attribute).

Arguments

object

an object of class "Spectra" or inheriting from this class

...
as.vector

Controls whether the IDs are returned as a vector or as a data.frame (defaults to TRUE)

value

character vector for new IDs

Methods

  • ids(object, ..., as.vector = TRUE)

  • ids(object) <- value

Author

Pierre Roudier pierre.roudier@gmail.com

Examples

Run this code

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

# Retrieving ids
ids(oz)

# Setting ids using a vector of values
ids(oz) <- seq_len(nrow(oz))
ids(oz)

# Setting ids using an attribute
oz$new_id <- seq_len(nrow(oz)) + 1000
ids(oz) <- ~ new_id
ids(oz)

Run the code above in your browser using DataLab