I am analyzing flower color spectra with the pavo package in R, and need to average all spectra from the same species. Spectra are all in one folder so I need to read all of them separately and average them so that I end up with one mean spectrum per plant species. I have different number of spectra for each species.
How do I specify to pavo that I want to aggregate spectra based on, say, the first four letters of each spectrum? In the example below, I would like to aggregate all polygal spectra and all larcun spectra. The pavo manual isn´t helping me and I don´t see any posts on pavo in this forum. Thanks in advance for any help.
I tried with the function aggspec, by I have not managed to aggregate based on the first letters of each spectrum file name.
I have only managed so far to read all the spectra, plot them, and obtain the variables that I need (hue, birghtness, chroma) for each file separately, but I need to average the spectra by species instead.
library(pavo)
#I create fake spectra, for two individuals of polygal species and three of larcun species
wl = seq(300, 560, 10)
polyg1 = c(2.381, 2.758, 2.923, 2.883, 3.127, 3.365, 3.364, 3.341, 3.42, 3.507, 3.534, 3.654, 3.782, 3.96, 4.125, 4.4, 4.691, 5.275, 5.888, 6.563, 7.275, 8.138, 8.866, 9.591, 10.121, 10.565, 10.895)
polyg22 = spec1 + runif(27, 0, 2)
larcun1 = spec1 + runif(27, 0, 2)
larcun2 = spec1 + runif(27, 0, 2)
larcun3 = spec1 + runif(27, 0, 2)
all.specs = cbind (wl, polyg1, polyg22, larcun1, larcun2, larcun3)
spectra1 = as.rspec(all.specs, interp = FALSE)
spectra.smooth = procspec(spectra1, opt = "smooth")
plot(spectra.smooth)
explorespec(spectra.smooth)