View source: R/fac2dummies_complex.R
| fac2dummies_complex | R Documentation |
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").
fac2dummies_complex(GADSdat, var)
GADSdat |
A |
var |
A character vector with the name of the factor variable. |
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".
Returns a GADSdat containing the newly computed variables.
## 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.