Let’s use the meats
data from {modeldata}
to
demonstrate baseline correction.
library(tidyverse)
library(tidymodels)
library(measure)
tidymodels_prefer()
theme_set(theme_light())
Before we can perform baseline correction, we need to reshape the
data. It is in a wide format where the columns represent the wavelength
and the value is transmittance. The step_baseline()
function operates on long format data. We can reshape this data with
{tidyr}
.
meats2 <-
meats %>%
rowid_to_column(var = "id") %>%
pivot_longer(
cols = starts_with("x_"),
names_to = "channel",
values_to = "transmittance"
) %>%
mutate(channel = str_extract(channel, "[:digit:]+") %>% as.integer())