JamesHWade / measure

The goal of measure is to be a recipes-like interface to tidymodels for analytical characterization data.
https://jameshwade.github.io/measure/
Other
5 stars 2 forks source link

Output steps #14

Closed topepo closed 8 months ago

topepo commented 11 months ago

These reformat the data into wide or long formats for easier use with recipe steps or model functions.

I'm note sure what to do about the wide naming. Right now it uses format() to make the names. I'd like to have integer increments but we don't know if we have the same location values between samples and/or data sets.

Any thoughts on that?

library(tidymodels)
library(measure)

data(meats)
meats <- meats %>% mutate(sample_id = row_number())
recipe(water + fat + protein ~ ., data = meats) %>%
  step_measure_input_wide(
    x_001:x_100, 
    location_values = seq(850, 1050, length.out = 100)
  ) %>%
  step_measure_output_wide() %>%
  prep() %>% 
  bake(new_data = NULL)
#> # A tibble: 215 × 104
#>    sample_id water   fat protein measure_0850.0000 measure_0852.0202
#>        <int> <dbl> <dbl>   <dbl>             <dbl>             <dbl>
#>  1         1  60.5  22.5    16.7              2.62              2.62
#>  2         2  46    40.1    13.5              2.83              2.84
#>  3         3  71     8.4    20.5              2.58              2.58
#>  4         4  72.8   5.9    20.7              2.82              2.82
#>  5         5  58.3  25.5    15.5              2.79              2.79
#>  6         6  44    42.7    13.7              3.01              3.02
#>  7         7  44    42.7    13.7              2.99              2.99
#>  8         8  69.3  10.6    19.3              2.53              2.53
#>  9         9  61.4  19.9    17.7              3.27              3.28
#> 10        10  61.4  19.9    17.7              3.40              3.41
#> # ℹ 205 more rows
#> # ℹ 98 more variables: measure_0854.0404 <dbl>, measure_0856.0606 <dbl>,
#> #   measure_0858.0808 <dbl>, measure_0860.1010 <dbl>, measure_0862.1212 <dbl>,
#> #   measure_0864.1414 <dbl>, measure_0866.1616 <dbl>, measure_0868.1818 <dbl>,
#> #   measure_0870.2020 <dbl>, measure_0872.2222 <dbl>, measure_0874.2424 <dbl>,
#> #   measure_0876.2626 <dbl>, measure_0878.2828 <dbl>, measure_0880.3030 <dbl>,
#> #   measure_0882.3232 <dbl>, measure_0884.3434 <dbl>, …

Created on 2023-10-11 with reprex v2.0.2