simplerspec
simplerspec copied to clipboard
dealing with infinite or missing values
Hi Philipp, Just wondering if you could help me identify how to debug the following error:
Error in svd(x, nu = 0, nv = k) : infinite or missing values in 'x'
This is coming from the following:
spectra <- read_opus_univ(vial_paths)
test_table <- spectra %>%
gather_spc() %>%
resample_spc(x_unit = 'wavenumber',
wn_interval=2) %>%
average_spc() %>%
preprocess_spc(select = 'sg_1_w21')
#### Read N ANalysis data ####
Nitrogen_Raw <- readxl::read_xlsx('Nitrogen_analysis.xlsx', skip = 5)[1:108,] %>%
mutate(sample_id = paste('Harvest',H,'Row',Row,'Range',Range, sep = ' ')) %>% # Create a sampleID
select(sample_id, H, Row, Range, `%C`, `%N`) %>% # Move sampleID to the front
mutate(sample_id = as.factor(sample_id)) %>%
rename(N = `%N`,
C = `%C`)
#### Join N analysis dataset with Spectral data ####
spec_chem <- join_spc_chem(spc_tbl = test_table, chem_tbl = Nitrogen_Raw, by = "sample_id")
pls_mod <- fit_pls(
spec_chem = spec_chem[!is.na(spec_chem$N),],
response =
N,
center = T,
scale = T,
print = T
)
I assume this is because there is missing data somewhere, but I don't know how exactly to clean it up. Any ideas would be appreciated!