Skip to contents

MLB Attendance

Usage

mlb_attendance(
  team_id = NULL,
  league_id = NULL,
  season = NULL,
  date = NULL,
  league_list_id = NULL
)

Arguments

team_id

Return attendance information for a particular team_id(s).

league_id

Return attendance information for a particular league_id(s). Format: '103,104'

season

Return attendance information for particular year(s).

date

Return attendance information on a particular date. Format: MM/DD/YYYY

league_list_id

Unique league list identifier to return a directory of attendance for a specific league list_id Valid values include:

  • milb_full

  • milb_short

  • milb_complex

  • milb_all

  • milb_all_nomex

  • milb_all_domestic

  • milb_noncomp

  • milb_noncomp_nomex

  • milb_domcomp

  • milb_intcomp

  • win_noabl

  • win_caribbean

  • win_all

  • abl

  • mlb

  • mlb_hist

  • mlb_milb

  • mlb_milb_hist

  • mlb_milb_win

  • baseball_all

Value

Returns a tibble with the following columns

col_nametypesdescription
openings_totalintegerTotal number of openings (games eligible to open).
openings_total_awayintegerTotal away openings.
openings_total_homeintegerTotal home openings.
openings_total_lostintegerOpenings lost (e.g. to rainouts).
games_totalintegerTotal games played.
games_away_totalintegerTotal away games.
games_home_totalintegerTotal home games.
yearcharacterSeason year (YYYY).
attendance_average_awayintegerAverage away-game attendance.
attendance_average_homeintegerAverage home-game attendance.
attendance_average_ytdintegerYear-to-date average attendance.
attendance_highintegerHighest single-game attendance.
attendance_high_datecharacterDate of the highest-attendance game.
attendance_lowintegerLowest single-game attendance.
attendance_low_datecharacterDate of the lowest-attendance game.
attendance_opening_averageintegerAverage opening-day attendance.
attendance_totalintegerTotal attendance for the period.
attendance_total_awayintegerTotal away attendance.
attendance_total_homeintegerTotal home attendance.
attendance_high_game_game_pkintegergame_pk of the highest-attendance game.
attendance_high_game_linkcharacterAPI link to the highest-attendance game.
attendance_high_game_day_nightcharacterDay/night status of the highest-attendance game.
attendance_high_game_content_linkcharacterAPI content link for the highest-attendance game.
attendance_low_game_game_pkintegergame_pk of the lowest-attendance game.
attendance_low_game_linkcharacterAPI link to the lowest-attendance game.
attendance_low_game_day_nightcharacterDay/night status of the lowest-attendance game.
attendance_low_game_content_linkcharacterAPI content link for the lowest-attendance game.
game_type_idcharacterGame type code (e.g. R for regular season).
game_type_descriptioncharacterGame type description.
team_idintegerMLB team ID.
team_namecharacterTeam name.
team_linkcharacterMLB Stats API relative team link.

Examples

# \donttest{
  try(mlb_attendance(team_id = 109, season = 2021))
#> ── MLB Attendance data from MLB.com ───────────────── baseballr 2.0.0 ──
#>  Data updated: 2026-06-12 14:09:22 UTC
#> # A tibble: 1 × 32
#>   openings_total openings_total_away openings_total_home
#>            <int>               <int>               <int>
#> 1            161                  80                  81
#> # ℹ 29 more variables: openings_total_lost <int>, games_total <int>,
#> #   games_away_total <int>, games_home_total <int>, year <chr>,
#> #   attendance_average_away <int>, attendance_average_home <int>,
#> #   attendance_average_ytd <int>, attendance_high <int>,
#> #   attendance_high_date <chr>, attendance_low <int>,
#> #   attendance_low_date <chr>, attendance_opening_average <int>,
#> #   attendance_total <int>, attendance_total_away <int>, …
# }