0

preparing recipe for training tidymodels I want to mutate when NA but is messing with the rest of dates

    library(tidyverse)
    
    df <- tibble(target = c(0, 1),
                date1= c(lubridate::ymd("2020-08-05"),NA))
              
    
    rec <- recipes::recipe(target ~ ., data = df) %>% 
      recipes::step_mutate(date1 = ifelse(is.na(date1), lubridate::ymd("1900-01-01"), date1)) %>%
      prep %>% juice
    
    > rec
    # A tibble: 2 x 2
        date1 target
   <dbl>  <dbl>
1  18479      0
2 -25567      1
Forge
  • 1,587
  • 1
  • 15
  • 36
  • Not familiar with recipes, but date1 columns is character class, not date, right? – zx8754 Nov 17 '21 at 10:19
  • no, all column dates are dates, i will fix the reprex – Forge Nov 17 '21 at 10:34
  • Great, I guess, now you need pass "1900-01-01" to ifelse as date, too. – zx8754 Nov 17 '21 at 13:42
  • The recipes framework is really best for statistical transformations that you learn from training data and then apply to new data or testing data (think scaling, or PCA components). I would probably recommend applying a transformation like this outside of a recipe, before you start your model data preprocessing. – Julia Silge Nov 20 '21 at 04:35
  • Sadly, this seems to be a bug. Messing with dates this way OMG!. You better send an issue at the tidymodels github. Falling back to ETL outside recipe is not solving nor answering the question. – useRj Nov 22 '21 at 10:42

0 Answers0