add_dummy_variables: Creates dummy variables

Description Usage Arguments Examples

View source: R/model_prep.R

Description

It uses 'tidyeval' and 'dplyr' to create dummy variables based for categorical variables.

Usage

1
2
add_dummy_variables(df, x, values = c(), auto_values = FALSE,
  remove_original = TRUE)

Arguments

df

A Local or remote data frame

x

Categorical variable

values

Possible known values of the categorical variable. If not passed then the function will take an additional step to figure the unique values of the variable.

auto_values

Safeguard argument to prevent the function from figuring the unique values if the values argument is empty. If it is ok for this function to obtain the unique values, set to TRUE. Defaults to FALSE.

remove_original

It removes the original variable from the returned table. Defaults to TRUE.

Examples

1
2
3
4
5
6
7
library(dplyr)

mtcars %>%
  add_dummy_variables(cyl, values = c(4, 6, 8))

mtcars %>%
  add_dummy_variables(cyl, auto_values = TRUE)

edgararuiz/modeldb documentation built on July 23, 2019, 8:14 a.m.