A.9 Summarize using reframe

The function reframe is similar to summarise except it doesn’t require the output to have one row (or one row per group, as we’ll see later). This finds all pairs of away and home teams, regardless if they played each other in this season (all pairs do play each other in the NBA, so this isn’t necessary for the NBA, but could be used in e.g. college basketball).

Code
pairs = d %>%
  reframe(expand.grid(away = unique(away), 
                      home = unique(home))) %>%
  filter(away != home)
dim(pairs)
head(pairs)
[1] 870   2
  away home
1  BKN  MIL
2  GSW  MIL
3  OKC  MIL
4  SAC  MIL
5  DEN  MIL
6  ORL  MIL

ZZZ Not a great example, maybe think of another one.