View source: R/factor2string.R
step_factor2string | R Documentation |
step_factor2string()
creates a specification of a recipe step that will
convert one or more factor vectors to strings.
step_factor2string(
recipe,
...,
role = NA,
trained = FALSE,
columns = FALSE,
skip = FALSE,
id = rand_id("factor2string")
)
recipe |
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 |
role |
Not used by this step since no new variables are created. |
trained |
A logical to indicate if the quantities for preprocessing have been estimated. |
columns |
A character string of the selected variable names. This field
is a placeholder and will be populated once |
skip |
A logical. Should the step be skipped when the
recipe is baked by |
id |
A character string that is unique to this step to identify it. |
prep()
has an option strings_as_factors
that defaults to TRUE
. If this
step is used with the default option, the strings produced by this step will
not be converted to factors.
Remember that categorical data that will be directly passed to a model should be encoded as factors. This step is helpful for ancillary columns (such as identifiers) that will not be computed on in the model.
An updated version of recipe
with the new step added to the
sequence of any existing operations.
When you tidy()
this step, a tibble is returned with
columns terms
and id
:
character, the selectors or variables selected
character, id of this step
The underlying operation does not allow for case weights.
Other dummy variable and encoding steps:
step_bin2factor()
,
step_count()
,
step_date()
,
step_dummy()
,
step_dummy_extract()
,
step_dummy_multi_choice()
,
step_holiday()
,
step_indicate_na()
,
step_integer()
,
step_novel()
,
step_num2factor()
,
step_ordinalscore()
,
step_other()
,
step_regex()
,
step_relevel()
,
step_string2factor()
,
step_time()
,
step_unknown()
,
step_unorder()
data(Sacramento, package = "modeldata")
rec <- recipe(~ city + zip, data = Sacramento)
make_string <- rec %>%
step_factor2string(city)
make_string <- prep(make_string,
training = Sacramento,
strings_as_factors = FALSE
)
make_string
# note that `city` is a string in recipe output
bake(make_string, new_data = NULL) %>% head()
# ...but remains a factor in the original data
Sacramento %>% head()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.