Arith: Arithmetical Operators for hyperSpec objects

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Arithmetical Operators: +, -, *, /, ^, %%, %/%, %*% for hyperSpec objects

Usage

 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
## S4 method for signature 'hyperSpec,hyperSpec'
Arith(e1, e2)

## S4 method for signature 'hyperSpec,numeric'
Arith(e1, e2)

## S4 method for signature 'hyperSpec,matrix'
Arith(e1, e2)

## S4 method for signature 'hyperSpec,missing'
Arith(e1, e2)

## S4 method for signature 'numeric,hyperSpec'
Arith(e1, e2)

## S4 method for signature 'matrix,hyperSpec'
Arith(e1, e2)

## S4 method for signature 'hyperSpec,hyperSpec'
x %*% y

## S4 method for signature 'hyperSpec,matrix'
x %*% y

## S4 method for signature 'matrix,hyperSpec'
x %*% y

Arguments

e1,e2

or

x,y

either two hyperSpec objects or

one hyperSpec object and matrix of same size as hyperSpec[[]] or

a vector which length equalling either the number of rows or the number of wavelengths of the hyperSpec object, or

a scalar (numeric of length 1).

Details

The arithmetical operators +, -, *, /, \^, %%, %/%, and %*% for hyperSpec objects.

You can use these operators in different ways:

1
2
3
4
5
6
7
e1 + e2
`+` (e1, e2)

x %*% y
`%*%`(x, y)

-x 

The arithmetical operators +, -, *, /, ^, %%, %/%, and %*% work on the spectra matrix of the hyperSpec object. They have their usual meaning (see Arithmetic). The operators work also with one hyperSpec object and a numeric object or a matrices of the same size as the spectra matrix of the hyperSpec object.

With numeric vectors sweep is most probably more appropriate.

If you want to calculate on the extra data as well, use the data.frame hyperSpec@data directly or as.data.frame (x).

Value

hyperSpec object with the new spectra matrix.

Author(s)

C. Beleites

See Also

sweep-methods for calculations involving a vector and the spectral matrix.

S4groupGeneric for group generic methods.

Arithmetic for the base arithmetic functions.

Comparison for comparison operators, Math for mathematical group generic functions (Math and Math2 groups) working on hyperSpec objects.

matmult for matrix multiplications with %*%.

Examples

1
2
3
4
5
flu + flu
1 / flu
all((flu + flu - 2 * flu)[[]] == 0)
-flu
flu / flu$c

Example output

Loading required package: lattice
Loading required package: grid
Loading required package: ggplot2
Loading required package: xml2
Package hyperSpec, version 0.99-20200527

To get started, try
   vignette ("hyperspec")
   package?hyperSpec 
   vignette (package = "hyperSpec")

If you use this package please cite it appropriately.
   citation("hyperSpec")
will give you the correct reference.

The project homepage is http://hyperspec.r-forge.r-project.org


hyperSpec object
   6 spectra
   3 data columns
   181 data points / spectrum
wavelength: lambda/nm [numeric] 405.0 405.5 ... 495 
data:  (6 rows x 3 columns)
   1. spc: I[fl]/"a.u." [matrix, array181] 54.3000 133.6027 ... 589.299 
   2. filename: filename [character] rawdata/flu1.txt rawdata/flu2.txt ... rawdata/flu6.txt 
   3. c: c / (mg / l) [numeric] 0.05 0.10 ... 0.3 
hyperSpec object
   6 spectra
   3 data columns
   181 data points / spectrum
wavelength: lambda/nm [numeric] 405.0 405.5 ... 495 
data:  (6 rows x 3 columns)
   1. spc: I[fl]/"a.u." [matrix, array181] 0.03683241 0.01496976 ... 0.003393863 
   2. filename: filename [character] rawdata/flu1.txt rawdata/flu2.txt ... rawdata/flu6.txt 
   3. c: c / (mg / l) [numeric] 0.05 0.10 ... 0.3 
[1] TRUE
hyperSpec object
   6 spectra
   3 data columns
   181 data points / spectrum
wavelength: lambda/nm [numeric] 405.0 405.5 ... 495 
data:  (6 rows x 3 columns)
   1. spc: I[fl]/"a.u." [matrix, array181] -27.15000 -66.80133 ... -294.6495 
   2. filename: filename [character] rawdata/flu1.txt rawdata/flu2.txt ... rawdata/flu6.txt 
   3. c: c / (mg / l) [numeric] 0.05 0.10 ... 0.3 
hyperSpec object
   6 spectra
   3 data columns
   181 data points / spectrum
wavelength: lambda/nm [numeric] 405.0 405.5 ... 495 
data:  (6 rows x 3 columns)
   1. spc: I[fl]/"a.u." [matrix, array181] 543.0000 668.0133 ... 982.165 
   2. filename: filename [character] rawdata/flu1.txt rawdata/flu2.txt ... rawdata/flu6.txt 
   3. c: c / (mg / l) [numeric] 0.05 0.10 ... 0.3 

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