fac2dummies_complex {eatGADS} | R Documentation |
Transform a complex factor variable to dummy variables.
Description
Convert a factor variable with complex factor levels (factor levels contain combinations of other factor levels) to dummy variables.
Dummy variables are coded 1
("yes"
) and 0
("no"
).
Usage
fac2dummies_complex(GADSdat, var)
Arguments
GADSdat |
A |
var |
A character vector with the name of the factor variable. |
Details
The basic functionality of this function is analogous to fac2dummies
. However, the function expects factor levels to only go
to 9
. Higher numbers are treated as combinations of factor levels, for example "13"
as "1"
and "3"
.
Value
Returns a GADSdat
containing the newly computed variables.
Examples
## create an example GADSdat
df_fac <- data.frame(id = 1:6, fac = c("Opt a", "Opt c, Opt b", "Opt c",
"Opt b", "Opt a, Opt b", "Opt a, Opt b, Opt c"), stringsAsFactors = TRUE)
g_fac <- import_DF(df_fac)
g_fac <- recodeGADS(g_fac, varName = "fac", oldValues = c(1, 2, 3, 4, 5, 6),
newValues = c(1, 12, 123, 2, 3, 23))
## transform factor variable
fac2dummies_complex(g_fac, "fac")
[Package eatGADS version 1.1.0 Index]