Skip to contents

load_nba_stats_matchups() reads the leagueseasonmatchups_regular-season_{per_mode}_{END year}.parquet files of the nba_stats_matchups release: one row per (offensive player, defensive player) pair. The tag publishes this table for the regular season only. load_nba_stats_matchups_rollup() reads the matchupsrollup_{season_type}_{per_mode}_{END year}.parquet files: one row per defender per offensive position (G/F/C) plus a TOTAL row.

matchup_min is "MM:SS" text in totals files and decimal minutes in pergame files, so reading both per modes makes it character. Pass one per_mode to keep the native types. Per-game matchups are in load_nba_stats_game_matchups().

Usage

load_nba_stats_matchups(
  seasons = most_recent_nba_stats_season(),
  per_mode = NULL,
  ...,
  dbConnection = NULL,
  tablename = NULL
)

load_nba_stats_matchups_rollup(
  seasons = most_recent_nba_stats_season(),
  season_type = NULL,
  per_mode = NULL,
  ...,
  dbConnection = NULL,
  tablename = NULL
)

Arguments

seasons

A vector of 4-digit years – the season's START year (e.g. 2024 for the 2024-25 season). Published coverage starts at 2017 (2017-18). Pass seasons = TRUE for every published season.

per_mode

"pergame" and/or "totals"; NULL (the default) reads both.

...

Additional arguments passed to an underlying function that writes the season data into a database.

dbConnection

A DBIConnection object, as returned by DBI::dbConnect()

tablename

The name of the data table within the database

season_type

"regular-season" and/or "playoffs"; NULL (the default) reads both.

Value

A hoopR_data tibble with one row per matchup pair per per mode (load_nba_stats_matchups()).

col_nametypesdescription
season_idcharacterstats.nba.com season code: a season-type digit (2 = regular season, 4 = playoffs) followed by the season's START year, e.g. '22024' = the 2024-25 regular season.
off_player_idintegerstats.nba.com identifier of the offensive player in the matchup.
off_player_namecharacterOffensive player's display name.
def_player_idintegerstats.nba.com identifier of the defender.
def_player_namecharacterDefender's display name.
gpintegerGames played in the split.
matchup_mincharacterTime matched up: 'MM:SS' text in 'totals' files, decimal minutes in 'pergame' files (character when both are loaded together).
partial_possnumericPossessions the pair was matched up for, apportioned by time (fractional).
player_ptsintegerPoints the offensive player scored while guarded by the defender.
team_ptsintegerPoints the offensive player's team scored while the pair was matched up.
matchup_astintegerAssists by the offensive player while guarded by the defender.
matchup_tovintegerTurnovers by the offensive player while guarded by the defender.
matchup_blkintegerBlocks by the defender on the offensive player's shots.
matchup_fgmintegerField goals made by the offensive player against the defender.
matchup_fgaintegerField goals attempted by the offensive player against the defender.
matchup_fg_pctnumericField-goal percentage (0-1) of the offensive player against the defender.
matchup_fg3_mintegerThree-pointers made by the offensive player against the defender.
matchup_fg3_aintegerThree-pointers attempted by the offensive player against the defender.
matchup_fg3_pctnumericThree-point percentage (0-1) of the offensive player against the defender.
help_blkintegerHelp-defense blocks credited to the matchup; stats.nba.com ships 0 in every row checked.
help_fgmintegerField goals made against help defense; stats.nba.com ships 0 in every row checked.
help_fgaintegerField goals attempted against help defense; stats.nba.com ships 0 in every row checked.
help_fg_percintegerField-goal percentage against help defense; stats.nba.com ships 0 in every row checked.
matchup_ftmintegerFree throws made by the offensive player on fouls by the defender.
matchup_ftaintegerFree throws attempted by the offensive player on fouls by the defender.
sflintegerShooting fouls committed by the defender on the offensive player.
matchup_time_secnumericTime matched up in seconds; present only in early 'totals' files (e.g. 2017-18).
seasonintegerEND year of the NBA season (2025 = 2024-25) – the published asset's own stamp, one more than the seasons argument.
season_typecharacterSeason type of the source file: 'regular-season' or 'playoffs' (the release file-name token).
per_modecharacterAggregation of the source file: 'pergame' (per-game averages) or 'totals' (season totals); stamped from the file name when the rows lack it.

A hoopR_data tibble with one row per defender per position per season type per per mode (load_nba_stats_matchups_rollup()).

col_nametypesdescription
season_idcharacterstats.nba.com season code: a season-type digit (2 = regular season, 4 = playoffs) followed by the season's START year, e.g. '22024' = the 2024-25 regular season.
positioncharacterOffensive position bucket the defender guarded: 'G', 'F' or 'C', plus a 'TOTAL' row summing the three.
percent_of_timenumericShare (0-1) of the defender's matchup time spent on this position ('TOTAL' = 1).
def_player_idintegerstats.nba.com identifier of the defender.
def_player_namecharacterDefender's display name.
gpintegerGames played in the split.
matchup_mincharacterTime the defender spent guarding this position: 'MM:SS' text in 'totals' files, decimal minutes in 'pergame' files (character when both are loaded together).
partial_possnumericPossessions the defender spent on this position, apportioned by time (fractional).
player_ptsintegerPoints scored by the offensive players of this position while guarded by the defender.
team_ptsintegerPoints scored by the opposing team while the defender guarded this position.
matchup_astintegerAssists by the guarded players of this position.
matchup_tovintegerTurnovers by the guarded players of this position.
matchup_blkintegerBlocks by the defender against this position.
matchup_fgmintegerField goals made against the defender by this position.
matchup_fgaintegerField goals attempted against the defender by this position.
matchup_fg_pctnumericField-goal percentage (0-1) allowed to this position.
matchup_fg3_mintegerThree-pointers made against the defender by this position.
matchup_fg3_aintegerThree-pointers attempted against the defender by this position.
matchup_fg3_pctnumericThree-point percentage (0-1) allowed to this position.
matchup_ftmintegerFree throws made by this position on the defender's fouls.
matchup_ftaintegerFree throws attempted by this position on the defender's fouls.
sflintegerShooting fouls the defender committed against this position.
seasonintegerEND year of the NBA season (2025 = 2024-25) – the published asset's own stamp, one more than the seasons argument.
season_typecharacterSeason type of the source file: 'regular-season' or 'playoffs' (the release file-name token).
per_modecharacterAggregation of the source file: 'pergame' (per-game averages) or 'totals' (season totals); stamped from the file name when the rows lack it.

Examples

# \donttest{
  try(load_nba_stats_matchups(seasons = most_recent_nba_stats_season() - 1,
                              per_mode = "totals"))
#> ───────────────────────────────────────────────────────────────── hoopR 3.2.0 ──
#> # A tibble: 147,303 × 30
#>    season_id off_player_id off_player_name   def_player_id def_player_name    gp
#>    <chr>             <int> <chr>                     <int> <chr>           <int>
#>  1 22025           1628389 Bam Adebayo             1628976 Wendell Carter…     5
#>  2 22025           1631230 Dominick Barlow         1630552 Jalen Johnson       4
#>  3 22025           1642270 Donovan Clingan          203497 Rudy Gobert         4
#>  4 22025            203497 Rudy Gobert             1642270 Donovan Clingan     4
#>  5 22025           1628976 Wendell Carter J…       1628389 Bam Adebayo         5
#>  6 22025            201142 Kevin Durant            1641739 Toumani Camara      4
#>  7 22025           1630552 Jalen Johnson           1631094 Paolo Banchero      4
#>  8 22025            201142 Kevin Durant            1630183 Jaden McDaniels     3
#>  9 22025           1628983 Shai Gilgeous-Al…       1641739 Toumani Camara      4
#> 10 22025           1631094 Paolo Banchero          1630552 Jalen Johnson       4
#> # ℹ 147,293 more rows
#> # ℹ 24 more variables: matchup_min <chr>, partial_poss <dbl>, player_pts <int>,
#> #   team_pts <int>, matchup_ast <int>, matchup_tov <int>, matchup_blk <int>,
#> #   matchup_fgm <int>, matchup_fga <int>, matchup_fg_pct <dbl>,
#> #   matchup_fg3_m <int>, matchup_fg3_a <int>, matchup_fg3_pct <dbl>,
#> #   help_blk <int>, help_fgm <int>, help_fga <int>, help_fg_perc <int>,
#> #   matchup_ftm <int>, matchup_fta <int>, sfl <int>, matchup_time_sec <dbl>, …
# }