Convert values to predefined integers
step_integer
creates a specification of a recipe
step that will convert new data into a set of integers based
on the original data values.
step_integer( recipe, ..., role = "predictor", trained = FALSE, strict = FALSE, zero_based = FALSE, key = NULL, skip = FALSE, id = rand_id("integer") ) ## S3 method for class 'step_integer' tidy(x, ...)
recipe |
A recipe object. The step will be added to the sequence of operations for this recipe. |
... |
One or more selector functions to choose which
variables will be used to create the integer variables. See
|
role |
For model terms created by this step, what analysis role should they be assigned?. By default, the function assumes that the new columns created by the original variables will be used as predictors in a model. |
trained |
A logical to indicate if the quantities for preprocessing have been estimated. |
strict |
A logical for whether the values should be returned as integers (as opposed to double). |
zero_based |
A logical for whether the integers should start at zero and new values be appended as the largest integer. |
key |
A list that contains the information needed to
create integer variables for each variable contained in
|
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. |
x |
A |
step_integer
will determine the unique values of
each variable from the training set (excluding missing values),
order them, and then assign integers to each value. When baked,
each data point is translated to its corresponding integer or a
value of zero for yet unseen data (although see the zero_based
argument above). Missing values propagate.
Factor inputs are ordered by their levels. All others are
ordered by sort
.
Despite the name, the new values are returned as numeric unless
strict = TRUE
, which will coerce the results to integers.
An updated version of recipe
with the new step added
to the sequence of existing steps (if any). For the tidy
method, a tibble with columns terms
(the selectors or
variables selected) and value
is a list column with the
conversion key.
library(modeldata) data(okc) okc$location <- factor(okc$location) okc_tr <- okc[1:100, ] okc_tr$age[1] <- NA okc_te <- okc[101:105, ] okc_te$age[1] <- NA okc_te$diet[1] <- "fast food" okc_te$diet[2] <- NA rec <- recipe(Class ~ ., data = okc_tr) %>% step_integer(all_predictors()) %>% prep(training = okc_tr) bake(rec, okc_te, all_predictors()) tidy(rec, number = 1)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.