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)

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))


wiscostret/fplscrapR documentation built on June 12, 2022, 8:03 a.m.