# Find 10 players with most games
if (require("Lahman")) {
players <- group_by(tbl_df(Batting), playerID)
games <- tally(players, G)
top_n(games, 10, n)
# A little nicer with \%>\%
tbl_df(Batting) %>%
group_by(playerID) %>%
tally(G) %>%
top_n(10)
# Find year with most games for each player
tbl_df(Batting) %>% group_by(playerID) %>% top_n(1, G)
}
Run the code above in your browser using DataCamp Workspace