step_binarize: Create binary variables from categorical and numeric...

View source: R/step-binarize.r

step_binarizeR Documentation

Create binary variables from categorical and numeric variables

Description

step_binarize() creates a specification of a recipe step that will create binary variables from categorical or numeric variables based on a provided set of passing or failing values.

Usage

step_binarize(
  recipe,
  ...,
  role = NA,
  trained = FALSE,
  pass = NULL,
  fail = NULL,
  skip = FALSE,
  id = rand_id("binarize")
)

Arguments

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 are affected by the step.

role

Not used by this step since no new variables are created.

trained

A logical value indicating whether the values used for binarization have been checked.

pass, fail

Vectors of values, matched to the variables, to be coded as 1 or 0, respectively.

skip

A logical value indicating whether the step should be skipped when the recipe is baked by bake.recipe().

id

A character string that is unique to this step, used to identify it.

Details

At least one of pass and fail must be provided, and if both are provided then values in neither will be converted to NA. For easier compatibility with other steps, binarization produces integer-valued variables taking the values 0 and 1 rather than logical variables.

Value

An updated version of recipe with the new step added to the sequence of existing steps (if any).

Examples

rec_test <- recipe(mtcars, mpg ~ .) %>%
  step_binarize(vs, am, pass = 1) %>%
  step_center(all_predictors(), -vs, -am) %>%
  step_scale(all_predictors(), -vs, -am) %>%
  prep()
bake(rec_test, mtcars)

corybrunson/imtidy documentation built on Sept. 15, 2022, 1:11 a.m.