0

准备训练 tidymodels 的配方我想在 NA 时变异,但与其余日期混淆

    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
4

0 回答 0