Converts data frames or matrices containing spectral data to rspec
object
Usage
as.rspec(
object,
whichwl = NULL,
interp = TRUE,
lim = NULL,
exceed.range = TRUE
)
is.rspec(object)
Arguments
- object
(required) a data frame or matrix containing spectra to process.
- whichwl
a numeric or character vector specifying which column contains wavelengths. If
NULL
(default), function searches for column containing equally spaced numbers and sets it as wavelengths "wl". If no wavelengths are found orwhichwl
is not given, returns arbitrary index values.- interp
whether to interpolate wavelengths in 1-nm bins (defaults to
TRUE
). It is rarely recommended to turn off this option, as uninterpolated spectra are incompatible with some downstream analyses, including notably colour vision models.- lim
vector specifying wavelength range to interpolate over (e.g.
c(300, 700)
).- exceed.range
logical. Should data be interpolated to the limits specified by
lim
iflim
exceeds the range of the actual data? Useful, and relatively safe, when the data range falls slightly withinlim
(e.g. 300.1 - 699 nm), but will produce spurious results iflim
far exceeds the range of input data. Defaults toTRUE
.
Value
an object of class rspec
for use in further pavo
functions
a logical value indicating whether the object is of class rspec
Author
Chad Eliason cme16@zips.uakron.edu
Examples
# Generate some fake reflectance data
fakedat <- data.frame(wl = 300:700, refl1 = rnorm(401), refl2 = rnorm(401))
head(fakedat)
#> wl refl1 refl2
#> 1 300 -1.3198173 -1.2601080
#> 2 301 -2.2864853 -1.4044018
#> 3 302 -0.7891444 1.8661513
#> 4 303 -0.8128883 -1.2918431
#> 5 304 -0.7274089 -0.8634225
#> 6 305 0.9984645 1.0373024
# Determine if is rspec object
is.rspec(fakedat)
#> [1] FALSE
# Convert to rspec object
fakedat2 <- as.rspec(fakedat)
#> wavelengths found in column 1
#> The spectral data contain 428 negative value(s),
#> which may produce unexpected results if used in models.
#> Consider using procspec() to correct them.
is.rspec(fakedat2)
#> [1] TRUE
head(fakedat2)
#> wl refl1 refl2
#> 1 300 -1.3198173 -1.2601080
#> 2 301 -2.2864853 -1.4044018
#> 3 302 -0.7891444 1.8661513
#> 4 303 -0.8128883 -1.2918431
#> 5 304 -0.7274089 -0.8634225
#> 6 305 0.9984645 1.0373024