spectra-methods: Retrieves or sets the spectra of a 'Spectra*' objects.

Description Details Value Methods About rowwise and colwise formats Author(s) See Also Examples

Description

Either retrieves the spectra matrix from a Spectra* object, or creates a Spectra* object from a "data.frame" object different interfaces detailed below.

Details

When applied to a Spectra* object, this functions simply returns the spectra it is storing.

If applied on a "data.frame" object, it is an helper function to create a Spectra* object. Two kind of interfaces are then available. value can be:

a vector:

Similarly to wl, the wavelengths of the spectra can be passed by a "numeric" vector. Alternatively, the names of the columns that contain the spectra information can be passed as a "character" vector.

a formula:

This interface is specific to inspectr. It follows a scheme where differents parts can be observed, the id column, the attributes columns, and the spectra columns, described by the wavelengths at which it has been measured:

Value

If applied on a "data.frame", either a Spectra or a SpectraDataFrame object. If applied on a Spectra* object, a matrix.

Methods

obj=data.frame

spectra(obj, ..., mode="rowwise") <- value

obj A "data.frame" object
mode A character describing the data representation of object ; it can be either 'rowwise' (default value) or 'colwise'. See Details section.
... Ignored
value A representation of the wavelengths of the Spectra* object to create. See details section.

obj=Spectra

spectra(obj)

obj A Spectra object
... Ignored

About rowwise and colwise formats

Generally, data used in spectroscopy can be represented into two formats:

rowwise

Each row represents a sample, each columns being the attributes that have been measured for this sample (reflectance in each wavelength, but also physical or chemical attributes)

colwise

Each row represents the reflectance for a given wavelength, each column being a sample. In this configuration, no attribute data can be added

Author(s)

Pierre Roudier pierre.roudier@gmail.com

See Also

wl, Spectra-class, SpectraDataFrame-class

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Loading example data
data(australia)
class(australia) # this is a simple data.frame
# structure of the data.frame: it is rowwise-formatted
big.head(australia) 

## CREATING Spectra OBJECTS
##

# Using spectra() to initiate a Spectra from 
# the data.frame
spectra(australia) <- sr_no ~ 350:2500
summary(australia)

# It is possible to select wavelengths using the formula interface
data(australia)
spectra(australia) <- sr_no ~ 350:5:2500
summary(australia)

data(australia)
spectra(australia) <- sr_no ~ 500:1800
summary(australia)

## CREATING SpectraDataFrame OBJECTS
##

# Using spectra() to initiate a SpectraDataFrame from 
# the data.frame
data(australia)
spectra(australia) <- sr_no ~ carbon + ph + clay ~ 350:2500
summary(australia)

# Selecting data to be included in the SpectradataFrame object
data(australia)
spectra(australia) <- sr_no ~ carbon ~ 350:2500
summary(australia)

# Forcing the creation of new ids using the id keyword in the 
# formula interface
data(australia)
spectra(australia) <- id ~ carbon ~ 350:2500
summary(australia)
ids(australia, as.vector = TRUE)

# Using the "..." short-hand to select all the remaining columns
data(australia)
spectra(australia) <- sr_no ~ ... ~ 350:2500
summary(australia)

## CREATING Spectra OBJECTS FROM
## BY-COLS-FORMATTED DATA
##

# For data formatted in the colwise format, 
# use the "colwise" mode

# Transforming data into colwise format
# for demonstration's sake
#
m <- melt_spectra(australia)
australia_by_col <- reshape2::acast(m, ... ~ sr_no)
australia_by_col <- data.frame(wl = rownames(australia_by_col), australia_by_col, check.names = FALSE)

# Here's colwise-formatted data 
big.head(australia_by_col)

# Convert it into Spectra object
spectra(australia_by_col, mode = "colwise") <- wl ~ ...
summary(australia_by_col)

# Then data can be added to promote it as a SpectraDataFrame
my.data <- features(australia, exclude_id = FALSE)
features(australia_by_col, key = 'sr_no') <- my.data
summary(australia_by_col)

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