dummify_across: Make Multiple Dummy (Binary) Variables At Once

Description Usage Arguments Value See Also Examples

View source: R/dummify_across.R

Description

This function allows you to make dummy variables across many variables at once. For example, if you have two variables called sex (with values "male","female","other") and marital status (with values "single", "married", "divorced", "widowed"), this function creates dummy variables for both sex and marital status based off of their unique values. This function is a wrapper of dummify() that allows multiple variables to be passed in the same function call. Currently, automatic renaming of variables and manual selection of reference categories is limited to dummify().

Usage

1
dummify_across(data, vars, reference = NULL)

Arguments

data

A dataframe containing the variables to be dummied.

vars

A list of column names or indices. Accepts variables integer, string, and factor values.

reference

If TRUE, it will leave the first value observed across each variable out as a reference category. Defaults to NULL, which leaves no variables as references.

Value

The inputted dataframe with additional columns containing all of the dummified variables

See Also

dummify

Examples

1
2
3
4
5
6
7
install.packages("palmerpenguins")

penguins<-palmerpenguins::penguins

dummify_across(penguins, c("species","island","sex"))
dummify_across(penguins, c(1,2,7))
dummify_across(penguins, c("species","island","sex"), reference = TRUE)

prlitics/dumdum documentation built on Aug. 12, 2020, 12:54 a.m.