dummy_encoder | R Documentation |
This function has been designed to encode multiple columns at once and allows the user to specify whether to drop the reference columns or retain them in the data
dummy_encoder(df, columns, map_fn = furrr::future_map, remove_original = TRUE)
df |
- data.frame object to pass to the function |
columns |
- vector of columns to be encoded for dummy encoding |
map_fn |
- choice of mapping function purrr:map or furr::future_map accepted |
remove_original |
- remove the variables that the dummy encodings are based off |
A tibble containing the dummy encodings
## Not run:
#Use the NHSR stranded dataset
df <- NHSRdatasets::stranded_data
#Create a function to select categorical variables
sep_categorical <- function(df){
cats <- df %>%
dplyr::select_if(is.character)
return(cats)
}
cats <- sep_categorical(df) %>%
dplyr::select(-c(admit_date))
#Dummy encoding
columns_vector <- c(names(cats))
dummy_encodings <- dummy_encoder(cats, columns_vector)
glimpse(dummy_encodings)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.