Learn R Programming

recipes (version 0.1.3)

add_role: Manually Add Roles

Description

add_role can add a role definition to an existing variable in the recipe.

Usage

add_role(recipe, ..., new_role = "predictor")

Arguments

recipe

An existing recipe().

...

One or more selector functions to choose which variables are being assigned a role. See selections() for more details.

new_role

A character string for a single role.

Value

An updated recipe object.

Details

If a variable is selected that currently has a role, the role is changed and a warning is issued.

Examples

Run this code
# NOT RUN {
data(biomass)

# Create the recipe manually
rec <- recipe(x = biomass)
rec
summary(rec)

rec <- rec %>%
  add_role(carbon, contains("gen"), sulfur, new_role = "predictor") %>%
  add_role(sample, new_role = "id variable") %>%
  add_role(dataset, new_role = "splitting variable") %>%
  add_role(HHV, new_role = "outcome")
rec

# }

Run the code above in your browser using DataLab