I have a data set that has individual basketball players statistics for each team for 17 years. In R I am trying to turn these player level observations into team level observations (for each year) by using a for loop which iterates through year and team and then aggregates the top three scorer's individual statistics (points, assists, rebounds etc). How would you recommend I proceed? (below you will find my current attempt, it only pulls the observations from the last teams and year of the data set and can't pull other statistics such as assists and rebound numbers from the 3 top scorers).
for (year in 2000:2017) {
for (team in teams) {
ts3_points =top_n(select(filter(bball, Tm == team & Year == year), PPG),3)
}
}