mlb_stats: *MLB Stats*

View source: R/mlb_stats.R

mlb_statsR Documentation

MLB Stats

Description

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,
  sit_codes = 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.

sit_codes

Situational split code(s) to filter on when stat_type = "statSplits" – e.g. "vl" (vs left), "vr" (vs right), "h" (home), "a" (away), "risp" (runners in scoring position). Multiple codes may be passed as a vector; see the MLB Stats API situationCodes endpoint for the full list.

Value

Returns a tibble with the following columns

col_name types description
total_splits integer Total number of splits in the response.
season character Season year for the statistic.
num_teams integer Number of teams the player appeared for.
rank integer Rank of the player for the sorted statistic.
age integer Player age during the season.
games_played integer Games played.
ground_outs integer Ground outs.
air_outs integer Air outs (fly outs).
runs integer Runs scored.
doubles integer Doubles.
triples integer Triples.
home_runs integer Home runs.
strike_outs integer Strikeouts.
base_on_balls integer Walks (bases on balls).
intentional_walks integer Intentional walks.
hits integer Hits.
hit_by_pitch integer Times hit by pitch.
avg character Batting average.
at_bats integer At bats.
obp character On-base percentage.
slg character Slugging percentage.
ops character On-base plus slugging.
caught_stealing integer Times caught stealing.
stolen_bases integer Stolen bases.
stolen_base_percentage character Stolen base success percentage.
caught_stealing_percentage character Caught stealing percentage.
ground_into_double_play integer Grounded into double plays.
number_of_pitches integer Total pitches seen.
plate_appearances integer Plate appearances.
total_bases integer Total bases.
rbi integer Runs batted in.
left_on_base integer Runners left on base.
sac_bunts integer Sacrifice bunts.
sac_flies integer Sacrifice flies.
babip character Batting average on balls in play.
ground_outs_to_airouts character Ratio of ground outs to air outs.
catchers_interference integer Times reached on catcher's interference.
at_bats_per_home_run character At bats per home run.
team_id integer Team MLBAM ID.
team_name character Team name.
team_link character API link to the team.
player_id integer Player MLBAM ID.
player_full_name character Player full name.
player_link character API link to the player.
player_first_name character Player first name.
player_last_name character Player last name.
league_id integer League MLBAM ID.
league_name character League name.
league_link character API link to the league.
sport_id integer Sport MLBAM ID.
sport_link character API link to the sport.
sport_abbreviation character Sport abbreviation (e.g., MLB).
position_code character Primary position code.
position_name character Primary position name.
position_type character Primary position type.
position_abbreviation character Primary position abbreviation.
splits_tied_with_offset list Players tied at the offset boundary.
splits_tied_with_limit list Players tied at the limit boundary.
player_pool character Player pool used (e.g., QUALIFIED).
type_display_name character Stat type display name.
group_display_name character Stat group display name.

Examples


  try(mlb_stats(stat_type = 'season', stat_group = 'hitting', season = 2021))


baseballr documentation built on Aug. 27, 2026, 1:07 a.m.