Skip to contents

MLB Stats

Usage

mlb_stats(
  stat_type = NULL,
  player_pool = NULL,
  game_type = NULL,
  team_id = NULL,
  position = NULL,
  stat_group = NULL,
  season = NULL,
  league_id = NULL,
  sport_ids = NULL,
  sort_stat = NULL,
  order = NULL,
  limit = 1000,
  offset = NULL
)

Arguments

stat_type

Stat type to return statistics for.

player_pool

There are 4 different types of player pools to return statistics for a particular player pool across a sport. Acceptable values include: All, Qualified, Rookies, or Qualified_rookies

game_type

Game type to return information for a particular statistic in a particular game type.

team_id

Team ID to return information and ranking for a particular statistic for a particular team.

position

Position to return statistics for a given position. Default to "Qualified" player pool Acceptable values include:

  • P

  • C

  • 1B

  • 2B

  • 3B

  • SS

  • LF

  • CF

  • RF

  • DH

  • PH

  • PR

  • BR

  • OF

  • IF

  • SP

  • RP

  • CP

  • UT

  • UI

  • UO

  • RHP

  • LHP

  • RHS

  • LHS

  • LHR

  • RHR

  • B

  • X

stat_group

Stat group to return information and ranking for a particular statistic in a particular group.

season

Year to return information and ranking for a particular statistic in a given year.

league_id

League ID to return statistics for a given league. Default to "Qualified" player pool.

sport_ids

The sport_id(s) to return information and ranking information for.

sort_stat

Sort return based on stat.

order

Order return based on either desc or asc.

limit

A limit to limit return to a particular number of records.

offset

An offset to returns i+1 as the first record in the set of players.

Value

Returns a tibble with the following columns

col_nametypesdescription
total_splitsintegerTotal number of splits in the response.
seasoncharacterSeason year for the statistic.
num_teamsintegerNumber of teams the player appeared for.
rankintegerRank of the player for the sorted statistic.
ageintegerPlayer age during the season.
games_playedintegerGames played.
ground_outsintegerGround outs.
air_outsintegerAir outs (fly outs).
runsintegerRuns scored.
doublesintegerDoubles.
triplesintegerTriples.
home_runsintegerHome runs.
strike_outsintegerStrikeouts.
base_on_ballsintegerWalks (bases on balls).
intentional_walksintegerIntentional walks.
hitsintegerHits.
hit_by_pitchintegerTimes hit by pitch.
avgcharacterBatting average.
at_batsintegerAt bats.
obpcharacterOn-base percentage.
slgcharacterSlugging percentage.
opscharacterOn-base plus slugging.
caught_stealingintegerTimes caught stealing.
stolen_basesintegerStolen bases.
stolen_base_percentagecharacterStolen base success percentage.
caught_stealing_percentagecharacterCaught stealing percentage.
ground_into_double_playintegerGrounded into double plays.
number_of_pitchesintegerTotal pitches seen.
plate_appearancesintegerPlate appearances.
total_basesintegerTotal bases.
rbiintegerRuns batted in.
left_on_baseintegerRunners left on base.
sac_buntsintegerSacrifice bunts.
sac_fliesintegerSacrifice flies.
babipcharacterBatting average on balls in play.
ground_outs_to_airoutscharacterRatio of ground outs to air outs.
catchers_interferenceintegerTimes reached on catcher's interference.
at_bats_per_home_runcharacterAt bats per home run.
team_idintegerTeam MLBAM ID.
team_namecharacterTeam name.
team_linkcharacterAPI link to the team.
player_idintegerPlayer MLBAM ID.
player_full_namecharacterPlayer full name.
player_linkcharacterAPI link to the player.
player_first_namecharacterPlayer first name.
player_last_namecharacterPlayer last name.
league_idintegerLeague MLBAM ID.
league_namecharacterLeague name.
league_linkcharacterAPI link to the league.
sport_idintegerSport MLBAM ID.
sport_linkcharacterAPI link to the sport.
sport_abbreviationcharacterSport abbreviation (e.g., MLB).
position_codecharacterPrimary position code.
position_namecharacterPrimary position name.
position_typecharacterPrimary position type.
position_abbreviationcharacterPrimary position abbreviation.
splits_tied_with_offsetlistPlayers tied at the offset boundary.
splits_tied_with_limitlistPlayers tied at the limit boundary.
player_poolcharacterPlayer pool used (e.g., QUALIFIED).
type_display_namecharacterStat type display name.
group_display_namecharacterStat group display name.

Examples

# \donttest{
  try(mlb_stats(stat_type = 'season', stat_group = 'hitting', season = 2021))
#> ── MLB Stats data from MLB.com ────────────────────── baseballr 2.0.0 ──
#>  Data updated: 2026-06-08 11:09:28 UTC
#> # A tibble: 132 × 61
#>    total_splits season num_teams  rank   age games_played ground_outs
#>           <int> <chr>      <int> <int> <int>        <int>       <int>
#>  1          132 2021           2     1    28          148         141
#>  2          132 2021           1     2    37          143         131
#>  3          132 2021           1     3    22          151         160
#>  4          132 2021           1     4    34          121         141
#>  5          132 2021           1     5    22          161         161
#>  6          132 2021           2     6    32          120         140
#>  7          132 2021           1     7    28          141         112
#>  8          132 2021           1     8    28          123         163
#>  9          132 2021           1     9    29          138         117
#> 10          132 2021           2    10    29          155         156
#> # ℹ 122 more rows
#> # ℹ 54 more variables: air_outs <int>, runs <int>, doubles <int>,
#> #   triples <int>, home_runs <int>, strike_outs <int>,
#> #   base_on_balls <int>, intentional_walks <int>, hits <int>,
#> #   hit_by_pitch <int>, avg <chr>, at_bats <int>, obp <chr>, slg <chr>,
#> #   ops <chr>, caught_stealing <int>, stolen_bases <int>,
#> #   stolen_base_percentage <chr>, caught_stealing_percentage <chr>, …
# }