Skip to content

Instantly share code, notes, and snippets.

@Keiku
Created January 11, 2017 05:32
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 Keiku/9bfc499b700f5a0fab2d574369934095 to your computer and use it in GitHub Desktop.
Save Keiku/9bfc499b700f5a0fab2d574369934095 to your computer and use it in GitHub Desktop.
Calculate frequency.
freq <- function(df, ...){
df %<>%
group_by_(...) %>%
summarise(count = n()) %>%
arrange_(.dots = ...) %>%
ungroup() %>%
mutate(
cum_count = cumsum(count),
percent = count / sum(count),
cum_percent = cumsum(percent)
)
return(df)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment