This function merges soil laboratory data with cleaned spectral (VNIR) data, performs preprocessing, and prepares inputs for calibration and model building.
merge_of_lab_and_spectrum(soil_data, data_NaturaSpec_cleaned)A list with the following elements:
Data frame of soil laboratory data (first 8 columns of merged dataset).
Matrix of VNIR spectral reflectance values (without metadata columns).
List of calibration sample indices for cross-validation (4 sets).
Vectors of indices corresponding to spectral bands to be removed (detector artifact regions around 1000 nm and 1800 nm).
Indices of spectral bands used for aggregation (columns 7–2146).
Indices of bands to be excluded from analysis.
Vector of spectral band names retained after removal.
A data frame containing soil laboratory measurements (must include a column named LAB_NUM).
A data frame containing cleaned spectral data
with columns Wavelength, LAB_NUM, and reflectance values.
The function performs the following steps:
Aggregates spectral data by wavelength and computes mean reflectance values.
Merges the soil and spectral datasets by LAB_NUM.
Separates soil variables and VNIR spectral matrix.
Creates calibration sample indices using random sampling.
Defines spectral bands to remove (detector artifact areas) and indices to be used in modeling.
# \donttest{
merged <- merge_of_lab_and_spectrum(soil_data, data_NaturaSpec_cleaned)
str(merged)
# }
Run the code above in your browser using DataLab