col_dummy: Apply explicit dummy coding to a data frame

Description Usage Arguments Value Examples

View source: R/col_dummy.R

Description

Apply explicit dummy coding to a data frame

Usage

1
col_dummy(data, factor, reference = NULL)

Arguments

data

A data frame to be passed in (e.g., via piping)

factor

A name of a factor column. Can be quoted or unquoted

reference

A string of the level that should be coded as the reference level. Defaults to the first level of the factor if one is not provided.

Value

A data.frame. A tibble passed into data is returned as a tibble.

Examples

1
2
3
4
5
6
7
# column name can be quoted or unquoted
col_dummy(iris, "Species", reference = "virginica")
col_dummy(iris, Species, reference = "virginica")

# model interpretation is the same
lm(Sepal.Length ~ Species, data = iris)
lm(Sepal.Length ~ Speciesversicolor + Speciesvirginica, data = col_dummy(iris, Species))

yjunechoe/junebug documentation built on July 9, 2021, 7:12 p.m.