data(Sacramento, package = "modeldata")
# convert factor to string to demonstrate
Sacramento$city <- as.character(Sacramento$city)
rec <- recipe(~ city + zip, data = Sacramento)
make_factor <- rec %>%
step_string2factor(city)
make_factor <- prep(make_factor,
training = Sacramento
)
make_factor
# note that `city` is a factor in recipe output
bake(make_factor, new_data = NULL) %>% head()
# ...but remains a string in the data
Sacramento %>% head()
Run the code above in your browser using DataLab