View source: R/dummiesToFactor.R
dummiesToFactor | R Documentation |
Convert multiple dummy variables into a single factor variable.
dummiesToFactor(dat, dummies, facVar, nameEmptyCategory = "_none_")
dat |
A |
dummies |
Character vector containing the names of the dummy variables in the |
facVar |
Name of the factor variable, that should be created. |
nameEmptyCategory |
a character of length 1 that defines the name of cases for which no dummy is equal to one. |
The content of a single factor variable can alternatively be stored in multiple dichotomous dummy variables coded with 0
/1
or NA
/1
. 1
always has to refer to "this category applies". The function requires factor levels to be exclusive (i.e. only one factor level applies per row.).
A data.frame
containing the newly created factor.
# Example data set
tdat <- data.frame(ID = 1:3, d1=c(1, 0, 0), d2 = c(0, 1, 0), d3 = c(0, 0, 1))
dummiesToFactor(tdat, dummies = c("d1", "d2", "d3"), facVar = "newFac")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.