Created
July 29, 2019 23:05
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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