
Last chance! 50% off unlimited learning
Sale ends in
step_factor2string
will convert one or more factor
vectors to strings.
step_factor2string(
recipe,
...,
role = NA,
trained = FALSE,
columns = FALSE,
skip = FALSE,
id = rand_id("factor2string")
)
A recipe object. The step will be added to the sequence of operations for this recipe.
One or more selector functions to choose variables
for this step. See selections()
for more details.
Not used by this step since no new variables are created.
A logical to indicate if the quantities for preprocessing have been estimated.
A character string of variables that will be
converted. This is NULL
until computed by
prep()
.
A logical. Should the step be skipped when the
recipe is baked by bake()
? While all operations are baked
when prep()
is run, some operations may not be able to be
conducted on new data (e.g. processing the outcome variable(s)).
Care should be taken when using skip = TRUE
as it may affect
the computations for subsequent operations.
A character string that is unique to this step to identify it.
An updated version of recipe
with the new step added to the
sequence of any existing operations.
When you tidy()
this step, a tibble with columns
terms
(the columns that will be affected) is returned.
prep
has an option strings_as_factors
that
defaults to TRUE
. If this step is used with the default
option, the string(s() produced by this step will be converted
to factors after all of the steps have been prepped.
Other dummy variable and encoding steps:
step_bin2factor()
,
step_count()
,
step_date()
,
step_dummy_extract()
,
step_dummy_multi_choice()
,
step_dummy()
,
step_holiday()
,
step_indicate_na()
,
step_integer()
,
step_novel()
,
step_num2factor()
,
step_ordinalscore()
,
step_other()
,
step_regex()
,
step_relevel()
,
step_string2factor()
,
step_unknown()
,
step_unorder()
# NOT RUN {
library(modeldata)
data(okc)
rec <- recipe(~ diet + location, data = okc)
rec <- rec %>%
step_string2factor(diet)
factor_test <- rec %>%
prep(training = okc,
strings_as_factors = FALSE) %>%
juice
# diet is a
class(factor_test$diet)
rec <- rec %>%
step_factor2string(diet)
string_test <- rec %>%
prep(training = okc,
strings_as_factors = FALSE) %>%
juice
# diet is a
class(string_test$diet)
tidy(rec, number = 1)
# }
Run the code above in your browser using DataLab