Skip to content

Instantly share code, notes, and snippets.

@mark-andrews
Last active November 21, 2020 16:52
Show Gist options
  • Save mark-andrews/bdf9c458d9f3584d1a59838350380ce7 to your computer and use it in GitHub Desktop.
Save mark-andrews/bdf9c458d9f3584d1a59838350380ce7 to your computer and use it in GitHub Desktop.
# View the dummy code of a categorical variable
# assumes package fastDummies is installed
# assumes tidyverse is installed
# Usage:
get_dummy_code <- function(Df, variable){
tmp_df <- fastDummies::dummy_cols(Df, remove_first_dummy = TRUE)
tmp_df <- dplyr::select(tmp_df, dplyr::starts_with(variable))
dplyr::arrange(dplyr::distinct(tmp_df), !!variable)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment