Description Usage Arguments Value Examples
This function allows you to construct a series of dummy variables from the values of a separate variable. E.g., if you have a variable called "race" with the following values: "White","Black","Asian","Native American/Alaskan Native", "Native Hawaiian", and "Other"–this function creates binary variables for each of the values, or however many the user specifies.
1 |
data |
A dataframe containing the variable to be dummied. |
var |
A string naming the variable to be dummied or the column index. Accepts variables integer, string, and factor values. |
reference |
An optional parameter that allows users to set and/or identify reference values with either TRUE, a character list,
or a named list. Defaults to NULL.If TRUE, |
dumNames |
An optional parameter that allows users to name the dummy variables they create with |
keepNA |
Defaults to TRUE. An optional parameter that allows users to decide if they want to consider NAs as values to be turned into a dummy column. |
The inputted dataframe with additional columns containing the dummified variables
1 2 3 4 5 6 7 8 9 | dummify(data = iris, var = "Species")
dummify(data = iris, var = 5)
dummify(data = iris, var = "Species", reference = TRUE)
dummify(data = iris, var = "Species", reference = "setosa")
dummify(data = iris, var = "Species", reference = "setosa", keepNA = FALSE)
dummify(data = iris, var = "Species", reference = c("setosa","virginica"))
dummify(data = iris, var = "Species", dumNames = c("BristlePointed","BlueFlag","Virginia"))
dummify(data = iris, var = "Species", dumNames = c("BristlePointed" = "setosa",
"BlueFlag" = "versicolor","Virginia" = "virginica"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.