Description Usage Arguments Examples
convert a column of categorical covariates into a number of columns with a binary flag for each category
1 | ordinal_to_binary_(df, col_name, prefix = NULL, overwrite = FALSE)
|
df |
data frame |
col_name |
column name to split into multiple binary flags |
prefix |
string name if want to specify a prefix to label the binary flag columns other than the original col_name |
overwrite |
overwrite any existing columns if the newly generated columns share the same name |
1 2 3 4 5 6 7 8 | library(dplyr)
df <- data_frame(OCC = c(1, 1, 2, 3))
df %>% ordinal_to_binary_("OCC")
df %>% ordinal_to_binary_("OCC", prefix = "OCCASION")
df2 <- data_frame(OCC = c(1, 1, 2, 3), OCC1 = 999)
df2 %>% ordinal_to_binary_("OCC")
df2 %>% ordinal_to_binary_("OCC", overwrite = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.