Suppose now we are interested in comparing the total BPS scores for each team in a given game? Here we take the example of game ID 1.

First we fetch the game stats using get_game_stats:

library(fplscrapR)

df <- get_game_stats(gameid=1)

Next we structure a coherent data frame of the two teams’ total BPS points, using R base’s rbind and dplyr:

library(dplyr)
## 
## Vedhæfter pakke: 'dplyr'
## De følgende objekter er maskerede fra 'package:stats':
## 
##     filter, lag
## De følgende objekter er maskerede fra 'package:base':
## 
##     intersect, setdiff, setequal, union
rbind( # combining the two objects containing the home and away team's BPS points
  data.frame(df$a[[10]],team="away"),
  data.frame(df$h[[10]],team="home")) %>%
  group_by(team) %>% # transformation to group and summarize the value (bps points scored by a given player in the game) at the team variable level
  summarize(sum(value))
## # A tibble: 2 x 2
##   team  `sum(value)`
##   <chr>        <int>
## 1 away           129
## 2 home           218