Skip to contents

Convert spectrum from wide to long form

Usage

spct_wide2long(
  spct,
  fixed.cols = "w.length",
  idfactor = "spct.idx",
  rm.spct.class = FALSE,
  ...
)

Arguments

spct

An object with spectral data.

fixed.cols

character Names of variables that should be copied unchanged for each spectrum.

idfactor

character The name of the factor to be added to the long-form object and used to store the original name of the columns as an index to the different spectra.

rm.spct.class

logical If true the returned object is a data frame.

...

Currently ignored.

Value

An object of the same class as spct or a data.frame with derived classes removed.

Details

Only objects of classes raw_spct, cps_spct, and object_spct normally contain multiple columns of spectral data. These are supported as well as generic_spct. Is the wide spectra contain multiple spectra in long form, the original idfactor is preserved.

Spectra that are already in long form, if passed as argument, are returned unchanged.

Because the classes defined for spectra have a well defined format, and known column names we can define a rather simple function for this operation.

Examples


spct_wide2long(white_led.raw_spct)
#> Object: raw_spct [6,204 x 3]
#> containing 3 spectra in long form
#> Wavelength range 187.82-1117.14 nm, step 0.41-0.48 nm 
#> Label: led_desk201 
#> Measured on 2016-12-19 16:19:57.298874 UTC 
#> Variables:
#>  w.length: Wavelength [nm]
#>  counts: Raw detector counts [number] 
#> --
#> # A tibble: 6,204 × 3
#>    w.length counts spct.idx
#>       <dbl>  <dbl> <fct>   
#>  1     188.  2298. counts_1
#>  2     188.  2217. counts_1
#>  3     189.  2186. counts_1
#>  4     189.  2188. counts_1
#>  5     190.  2423. counts_1
#>  6     190.  2451. counts_1
#>  7     191.  2459. counts_1
#>  8     191.  2466. counts_1
#>  9     192.  2484. counts_1
#> 10     192.  2466. counts_1
#> # ℹ 6,194 more rows
spct_wide2long(white_led.cps_spct)
#> Object: cps_spct [2,068 x 2]
#> Wavelength range 187.82-1117.14 nm, step 0.41-0.48 nm 
#> Label: led_desk201 
#> Measured on 2016-12-19 16:19:57.298874 UTC 
#> Data acquired with 'MayaPro2000' s.n. MAYP11278
#> grating 'HC1', slit '010s'
#> diffuser 'unknown'
#> integ. time (s): 0.233, 1.43, 5
#> total time (s): 10, 10, 10
#> counts @ peak (% of max): 94.2
#> Variables:
#>  w.length: Wavelength [nm]
#>  cps: Detector counts [number s-1] 
#> --
#> # A tibble: 2,068 × 2
#>    w.length     cps
#>       <dbl>   <dbl>
#>  1     188.  -0.419
#>  2     188.  -0.340
#>  3     189.  -0.660
#>  4     189.   0.513
#>  5     190. -11.1  
#>  6     190.  22.6  
#>  7     191.  57.7  
#>  8     191.  53.9  
#>  9     192.  77.4  
#> 10     192.  77.7  
#> # ℹ 2,058 more rows
spct_wide2long(Ler_leaf.spct)
#> Object: generic_spct [4,802 x 3]
#> containing 2 spectra in long form
#> Wavelength range 250-850 nm, step 0.25 nm 
#> Label: Ler_06_black.spct 
#> Measured on 2017-07-03 13:17:09.548817 UTC 
#> Variables:
#>   
#> --
#> # A tibble: 4,802 × 3
#>    w.length  value spct.idx
#>       <dbl>  <dbl> <fct>   
#>  1     250  0.0467 Rfr     
#>  2     250. 0.0467 Rfr     
#>  3     250. 0.0467 Rfr     
#>  4     251. 0.0467 Rfr     
#>  5     251  0.0467 Rfr     
#>  6     251. 0.0467 Rfr     
#>  7     252. 0.0467 Rfr     
#>  8     252. 0.0467 Rfr     
#>  9     252  0.0467 Rfr     
#> 10     252. 0.0467 Rfr     
#> # ℹ 4,792 more rows