Skip to content

Instantly share code, notes, and snippets.

@mhweber
Created July 29, 2019 23:05
Show Gist options
  • Select an option

  • Save mhweber/a9a75f1cc020cdd7fdf9fe4df8f03681 to your computer and use it in GitHub Desktop.

Select an option

Save mhweber/a9a75f1cc020cdd7fdf9fe4df8f03681 to your computer and use it in GitHub Desktop.
Dplyr summarize to get most frequently occurring categorical value by a grouping variable
library("Lahman")
# Aggregation
Batting %>%
group_by(playerID) %>%
summarize(most_team = names(which.max(table(teamID, exclude=NULL))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment