I need to create a recipe using the recipes package from tidymodels. In one of the steps, I need to convert ordered factors to their ordinal score. But there seems to be no function that I can use in order to select all ordered factors.
I know that there is a function called all_nominal()
, but that matches every column that is a factor, which can be either ordered or unordered. I have also tried has_type("ordered")
but that does not work either.
Currently, I have to manually enter the column names. Is there an easier way to do this?
Below is an example of what I want to do:
library(mlbench)
data("BreastCancer")
rec <- recipe(Class ~ ., BreastCancer) %>%
# Here, I want to select all ordered nominals instead of
# listing them by name. Should there be a function
# all_ordinal in recipes? Or is there another way
# to accomplish this?
step_ordinalscore(Cl.thickness,
Cell.size,
Cell.shape,
Marg.adhesion,
Epith.c.size)
Any help is welcome, thanks.
There isn't a special selector function for ordered factors, but you can find them yourself and then use that vector of names to
step_ordinalscore()
.Created on 2020-10-19 by the reprex package (v0.3.0.9001)