TOPboxes | R Documentation |
Calculate Team, Opponents and Players box scores (Tbox, Obox and Pbox)
TOPboxes(data, team)
data |
a data frame containing play-by-play data (see Details) |
team |
character, indicating the name of the team |
To compute Tbox
and Obox
, the function needs the following variables:
game_id
, playlength
, ShotType
, points
, result
, team
, oreb
, dreb
, PF
, turnover
, assist
, block
and steal
.
If any of these variables is missing, an error message is displayed.
To compute Pbox
, also the variables player, a1
. . . a5
, h1
. . . h5
and hometeam
are needed.
If any is omitted, only Tbox
and Obox
are given in output.
Note that the variables assist
, block
and steal
can contain the logical indicator of whether the corresponding event has occurred (TRUE/FALSE or numerical 0/1) or the name of the involved player (character).
In the former case, Tbox
and Obox
are fully computed, while the variables AST
, BLK
and STL
are missing in the Pbox
data frame.
In the latter case, all the data frames Tbox
, Obox
and Pbox
are fully computed.
TOPboxes
omits the computation of the variables W
(Games won) and L
(Games lost).
In fact, since we aim at computing box scores starting from whatever portion of play-by-play data (e.g., only a part of a game), in some cases, calculating the number of won and lost games does not make sense.
A list with the following elements
Tbox
, the data frame of team box scores
Obox
, the data frame of opponents box scores
Pbox
, the data frame of player box scores
Marco Sandri, Paola Zuccolotto, Marica Manisera (basketballanalyzer.help@unibs.it)
P. Zuccolotto, M. Manisera and M. Sandri (2026) Advanced Basketball Data Science: With Applications in R. CRC Press.
P. Zuccolotto and M. Manisera (2020) Basketball Data Science: With Applications in R. CRC Press.
PbPmanipulation
library(operators)
library(dplyr)
PbP <- PbPmanipulation(PbP.BDB)
PbP <- PbP %>%
mutate(oreb = type %~% "rebound offensive",
dreb = type %~% "rebound defensive",
turnover = event_type=="turnover",
PF = (event_type == "foul") & !(type %~% "technical") ) %>%
mutate(across(c(player, assist, steal, block, h1:h5, a1:a5), as.character)) %>%
as.data.frame()
out <- TOPboxes(PbP, team="GSW")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.