Hi there. I am trying to create a recipe with a step function that takes the input character variable and bins it into various categories depending on the value of the variable. For example
my_custom_function(word){
if(str_detect(word, "a")) return("A")
if(str_detect(word, "b")) return("B")
return("C")
main_rec <- recipe(y ~ word, df) |>
step_mutate_at(word, fn = list(my_ custom_function))
# OR
main_rec <- recipe(y ~ word, df) |>
step_mutate(word = as.factor(map_chr(word, .f = my_custom_function)))
It throws an error either not recognizing the custom function ot map_chr or str_detect.
What am I doing wrong?
Any help is appreciated.