dummify: Turn variable into vector of dummy variables

Description Usage Arguments Value Examples

View source: R/dummify.R

Description

Takes any variable and splits into separate variables by unique value, with a binary indicator (0/1) for each. Uses stats::model.matrix to perform the dummifying. By default, all new dummy variables have the name var_'unique_value' where var_ is the supplied variable name and unique_value is the value for which the indicator is 1. Set 'prefix = FALSE' to remove var_ from the new variable name. By default, this function errors when var has more than 20 distinct values. Set 'force = TRUE' to dummify anyway. TODO: Check how missing values are handled. Allow ... list of variable input

Usage

1
dummify(df, var, prefix = TRUE, force = FALSE)

Arguments

df

a tbl

var

variable to dummify (will be coerced to character before dummifying)

prefix

(default = TRUE) prepend var name to dummy variable names?

force

(default = FALSE) allow creation of more than 20 dummies?

Value

the original tbl with dummy variables added on the end.

Examples

1
dummify(iris, Species)

williamlief/liefTools documentation built on Jan. 1, 2020, 6:48 p.m.