dummy_vars {predRupdate} | R Documentation |
Create dummy variables for all categorical/factor variables in a data.frame
Description
Create dummy/indicator variables for all categorical variables in a data.frame. Can be used as a pre-processing step before calling other functions within the package.
Usage
dummy_vars(df)
Arguments
df |
a data.frame on which to make dummy variables for each categorical/factor variable, based on contrasts. |
Value
a data.frame matching df
but where each categorical
variable in df
is replaced with indicator variables. All
combinations of the indicator/dummy variable are returned. Naming
convention of the new dummy variables is variable_level. For example, a
factor variable in df
named "colour" with levels "red", "green" and
"purple" will be replaced with three columns (the new dummy variables),
named colour_red, colour_green and colour_purple.
See Also
Examples
dummy_vars(data.frame("Colour" = factor(sample(c("red",
"azure",
"green",
"white"),
500,
replace = TRUE))))
[Package predRupdate version 0.1.1 Index]