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_nametypes
total_splitsinteger
seasoncharacter
num_teamsinteger
rankinteger
games_playedinteger
ground_outsinteger
air_outsinteger
runsinteger
doublesinteger
triplesinteger
home_runsinteger
strike_outsinteger
base_on_ballsinteger
intentional_walksinteger
hitsinteger
hit_by_pitchinteger
avgcharacter
at_batsinteger
obpcharacter
slgcharacter
opscharacter
caught_stealinginteger
stolen_basesinteger
stolen_base_percentagecharacter
ground_into_double_playinteger
number_of_pitchesinteger
plate_appearancesinteger
total_basesinteger
rbiinteger
left_on_baseinteger
sac_buntsinteger
sac_fliesinteger
babipcharacter
ground_outs_to_airoutscharacter
catchers_interferenceinteger
at_bats_per_home_runcharacter
team_idinteger
team_namecharacter
team_linkcharacter
player_idinteger
player_full_namecharacter
player_linkcharacter
player_first_namecharacter
player_last_namecharacter
league_idinteger
league_namecharacter
league_linkcharacter
sport_idinteger
sport_linkcharacter
sport_abbreviationcharacter
position_codecharacter
position_namecharacter
position_typecharacter
position_abbreviationcharacter
splits_tied_with_offsetlist
splits_tied_with_limitlist
player_poolcharacter
type_display_namecharacter
group_display_namecharacter

Examples

# \donttest{
  try(mlb_stats(stat_type = 'season', stat_group = 'hitting', season = 2021))
#> ── MLB Stats data from MLB.com ────────────────────── baseballr 1.2.0 ──
#>  Data updated: 2022-04-30 07:16:38 UTC
#> # A tibble: 132 × 59
#>    total_splits season num_teams  rank games_played ground_outs air_outs
#>           <int> <chr>      <int> <int>        <int>       <int>    <int>
#>  1          132 2021           2     1          148         141      153
#>  2          132 2021           1     2          143         131      174
#>  3          132 2021           1     3          151         160       97
#>  4          132 2021           1     4          121         141      130
#>  5          132 2021           1     5          161         161      147
#>  6          132 2021           2     6          120         140       86
#>  7          132 2021           1     7          141         112       97
#>  8          132 2021           1     8          123         163       83
#>  9          132 2021           1     9          138         117      135
#> 10          132 2021           2    10          155         156      180
#> # … with 122 more rows, and 52 more variables: 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>, ground_into_double_play <int>,
#> #   number_of_pitches <int>, plate_appearances <int>, …
# }