A.11 Summaries by team using group_by
Now we can find average points scored by each team. When we use group_by
, whatever operations come next will be done separately for each group.
# A tibble: 30 × 3
team score opp.score
<chr> <dbl> <dbl>
1 ATL 114. 112.
2 BKN 113. 112.
3 BOS 112. 104.
4 CHA 115. 115.
5 CHI 112. 112
6 CLE 108. 106.
7 DAL 108. 105.
8 DEN 113. 110.
9 DET 105. 113.
10 GSW 111 105.
# ℹ 20 more rows
Here the summarise
operations that we saw before is performed separately on each team
instead of for the entire data frame.
Sometimes it can help to visualize this in our minds by pretending that group_by(team)
gives you separate data frames for each team. Then whatever operation comes next is performed on each of those data frame.