Skip to content

Instantly share code, notes, and snippets.

@dwhdai
Created September 30, 2019 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwhdai/c743609dc48382bc858d6f37296bd4e0 to your computer and use it in GitHub Desktop.
Save dwhdai/c743609dc48382bc858d6f37296bd4e0 to your computer and use it in GitHub Desktop.
Group percentage of categorical variable
percent <- function(data, group){
group <- enquo(group)
data %>%
group_by(!!group) %>%
summarise(percentage = n()/nrow(data))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment