'Fold1: preprocessor 1/1, model 1/6: Error in if (!all(o)) : missing value where TRUE/FALSE needed

I'm a student fairly new to r and machine learning, and I'm trying to finish my final report. I want to use multinominal logistic regression through cross-validation to tune my parameters, but I keep receiving this error : Fold1: preprocessor 1/1, model 1/6: Error in if (!all(o)) : missing value where TRUE/FALSE needed

When trying to fix it, I think the error is from the NAs that haven't been replaced by means and modes. I have used step_impute_median and step_impute_mode to replace my NAs, but when viewing it, all the NAs are still there. Why didn't the step function work? what can I do to fix this?

the following is my code, thank you!


library(tidymodels)
young <- read.csv("https://kirk.cdkm.com/convert/file/st4u2ucw5qg4f4lrfrfkswjfetflr66d/responses.html")
young <- young %>%
mutate(Group=ifelse(Friends.versus.money>3,"friend",ifelse(Friends.versus.money==3,"mo_fr","money"))) %>% 
  select(-Friends.versus.money)

glmnet_model <- 
  multinom_reg(
    penalty=tune(), mixture = tune()) %>% 
  set_engine("glmnet") %>% 
  set_mode("classification")

glmnet_param <- parameters(glmnet_model)
glmnet_param <- glmnet_param %>% 
  update(penalty=penalty(c(-4,0)),
         mixture = mixture(c(0,1)))
glmnet_grid <- glmnet_param %>% 
  grid_regular(levels = c(penalty = 50, mixture = 6))

glmnet_rec <- 
  recipe(Group ~., data = young) %>% 
  step_impute_median(all_numeric_predictors()) %>%
  step_normalize(all_numeric_predictors()) %>%
  step_impute_mode(all_nominal_predictors()) %>% 
  step_dummy(all_nominal_predictors())

glmnet_wflow <- 
  workflow() %>% 
  add_model(glmnet_model) %>% 
  add_recipe(glmnet_rec)

fvm_class_metrics <- metric_set(accuracy, f_meas)

fvm_folds <- 
  vfold_cv(young, v = 5, repeats = 1)

glmnet_tune <- 
  glmnet_wflow %>% 
  tune_grid(
    fvm_folds,
    grid = glmnet_grid,
    metrics = fvm_class_metrics  )


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source