Learn R Programming

geoSpectral (version 0.17.5)

Spectra-coerce: Conversion between Spectra and data.frame objects

Description

Converting Spectra object to data.frame is straightforward while the conversion in the opposite direction requires a set of attributes to be present in the source data.frame object. These attributes are generally created during the conversion of a Spectra object into data.frame, they can also be manually set if they are non-existant (see the example below).

Arguments

from

The input object

to

Name of the class of output object

Examples

Run this code
# NOT RUN {
#Convert a Spectra object to data.frame
sp <- spc.example_spectra()
df <- as(sp, "data.frame")
class(df); dim(df)
attributes(df)

#Convert the data.frame back to Spectra
sp2 <- as(df, "Spectra")

#Convert a bare data.frame to Spectra with minimal attributes
df2 <- data.frame(ch1=c(1,2,3,4), ch2=c(5,6,7,8), TIME=Sys.time()+1:4, LAT=1:4, LON=5:8)
attr(df2, "Units") <- "m-1"
attr(df2, "Wavelengths") <- c(500, 600)
attr(df2, "ShortName") <- "abs"
as(df2, "Spectra")
# }

Run the code above in your browser using DataLab