Learn R Programming

baseballr (version 1.6.0)

fg_batter_leaders: Scrape Batter Leaderboards from FanGraphs

Description

This function allows you to scrape all leaderboard statistics (basic and advanced) from FanGraphs.com.

Usage

fg_batter_leaders(
  age = "",
  pos = "all",
  stats = "bat",
  lg = "all",
  qual = "0",
  startseason = "2023",
  endseason = "2023",
  startdate = "",
  enddate = "",
  month = "0",
  hand = "",
  team = "0",
  pageitems = "10000",
  pagenum = "1",
  ind = "0",
  rost = "0",
  players = "",
  type = "8",
  postseason = "",
  sortdir = "default",
  sortstat = "WAR"
)

Value

A data frame of batter data.

col_nametypes
Seasoninteger
team_namecharacter
Batscharacter
xMLBAMIDinteger
PlayerNameRoutecharacter
PlayerNamecharacter
playeridinteger
Ageinteger
AgeRngcharacter
SeasonMininteger
SeasonMaxinteger
Ginteger
ABinteger
PAinteger
Hinteger
1Binteger
2Binteger
3Binteger
HRinteger
Rinteger
RBIinteger
BBinteger
IBBinteger
SOinteger
HBPinteger
SFinteger
SHinteger
GDPinteger
SBinteger
CSinteger
AVGnumeric
GBinteger
FBinteger
LDinteger
IFFBinteger
Pitchesinteger
Ballsinteger
Strikesinteger
IFHinteger
BUinteger
BUHinteger
BB_pctnumeric
K_pctnumeric
BB_Knumeric
OBPnumeric
SLGnumeric
OPSnumeric
ISOnumeric
BABIPnumeric
GB_FBnumeric
LD_pctnumeric
GB_pctnumeric
FB_pctnumeric
IFFB_pctnumeric
HR_FBnumeric
IFH_pctnumeric
BUH_pctnumeric
TTO_pctnumeric
wOBAnumeric
wRAAnumeric
wRCnumeric
Battingnumeric
Fieldingnumeric
Replacementnumeric
Positionalnumeric
wLeaguenumeric
Defensenumeric
Offensenumeric
RARnumeric
WARnumeric
WAROldnumeric
Dollarsnumeric
BaseRunningnumeric
Spdnumeric
wRC_plusnumeric
wBsRnumeric
WPAnumeric
WPA_minusnumeric
WPA_plusnumeric
RE24numeric
REWnumeric
pLInumeric
PHinteger
WPA_LInumeric
Clutchnumeric
FBall_pctnumeric
FBvnumeric
SL_pctnumeric
SLvnumeric
CT_pctnumeric
CTvnumeric
CB_pctnumeric
CBvnumeric
CH_pctnumeric
CHvnumeric
SF_pctnumeric
SFvnumeric
XX_pctnumeric
wFBnumeric
wSLnumeric
wCTnumeric
wCBnumeric
wCHnumeric
wSFnumeric
wFB_Cnumeric
wSL_Cnumeric
wCT_Cnumeric
wCB_Cnumeric
wCH_Cnumeric
wSF_Cnumeric
O-Swing_pctnumeric
Z-Swing_pctnumeric
Swing_pctnumeric
O-Contact_pctnumeric
Z-Contact_pctnumeric
Contact_pctnumeric
Zone_pctnumeric
F-Strike_pctnumeric
SwStr_pctnumeric
CStr_pctnumeric
C+SwStr_pctnumeric
Pullinteger
Centinteger
Oppointeger
Softinteger
Medinteger
Hardinteger
bipCountinteger
Pull_pctnumeric
Cent_pctnumeric
Oppo_pctnumeric
Soft_pctnumeric
Med_pctnumeric
Hard_pctnumeric
UBRnumeric
GDPRunsnumeric
AVG+numeric
BB_pct+numeric
K_pct+numeric
OBP+numeric
SLG+numeric
ISO+numeric
BABIP+numeric
LD_pct+numeric
GB_pct+numeric
FB_pct+numeric
HRFB_pct+numeric
Pull_pct+numeric
Cent_pct+numeric
Oppo_pct+numeric
Soft_pct+numeric
Med_pct+numeric
Hard_pct+numeric
xwOBAnumeric
xAVGnumeric
xSLGnumeric
PPTVinteger
CPTVinteger
BPTVinteger
DSVinteger
DGVinteger
BTVinteger
rPPTVnumeric
rBPTVnumeric
EBVinteger
ESVinteger
rFTeamVnumeric
rBTeamVnumeric
rTVnumeric
pfx_FA_pctnumeric
pfx_FC_pctnumeric
pfx_FS_pctnumeric
pfx_FO_pctnumeric
pfx_SI_pctnumeric
pfx_SL_pctnumeric
pfx_CU_pctnumeric
pfx_KC_pctnumeric
pfx_EP_pctnumeric
pfx_CH_pctnumeric
pfx_SC_pctnumeric
pfx_vFAnumeric
pfx_vFCnumeric
pfx_vFSnumeric
pfx_vFOnumeric
pfx_vSInumeric
pfx_vSLnumeric
pfx_vCUnumeric
pfx_vKCnumeric
pfx_vEPnumeric
pfx_vCHnumeric
pfx_vSCnumeric
pfx_FA-Xnumeric
pfx_FC-Xnumeric
pfx_FS-Xnumeric
pfx_FO-Xnumeric
pfx_SI-Xnumeric
pfx_SL-Xnumeric
pfx_CU-Xnumeric
pfx_KC-Xnumeric
pfx_EP-Xnumeric
pfx_CH-Xnumeric
pfx_SC-Xnumeric
pfx_FA-Znumeric
pfx_FC-Znumeric
pfx_FS-Znumeric
pfx_FO-Znumeric
pfx_SI-Znumeric
pfx_SL-Znumeric
pfx_CU-Znumeric
pfx_KC-Znumeric
pfx_EP-Znumeric
pfx_CH-Znumeric
pfx_SC-Znumeric
pfx_wFAnumeric
pfx_wFCnumeric
pfx_wFSnumeric
pfx_wFOnumeric
pfx_wSInumeric
pfx_wSLnumeric
pfx_wCUnumeric
pfx_wKCnumeric
pfx_wEPnumeric
pfx_wCHnumeric
pfx_wSCnumeric
pfx_wFA_Cnumeric
pfx_wFC_Cnumeric
pfx_wFS_Cnumeric
pfx_wFO_Cnumeric
pfx_wSI_Cnumeric
pfx_wSL_Cnumeric
pfx_wCU_Cnumeric
pfx_wKC_Cnumeric
pfx_wEP_Cnumeric
pfx_wCH_Cnumeric
pfx_wSC_Cnumeric
pfx_O-Swing_pctnumeric
pfx_Z-Swing_pctnumeric
pfx_Swing_pctnumeric
pfx_O-Contact_pctnumeric
pfx_Z-Contact_pctnumeric
pfx_Contact_pctnumeric
pfx_Zone_pctnumeric
pfx_Pacenumeric
pi_CH_pctnumeric
pi_CU_pctnumeric
pi_FA_pctnumeric
pi_FC_pctnumeric
pi_FS_pctnumeric
pi_SB_pctnumeric
pi_SI_pctnumeric
pi_SL_pctnumeric
pi_vCHnumeric
pi_vCUnumeric
pi_vFAnumeric
pi_vFCnumeric
pi_vFSnumeric
pi_vSBnumeric
pi_vSInumeric
pi_vSLnumeric
pi_CH-Xnumeric
pi_CU-Xnumeric
pi_FA-Xnumeric
pi_FC-Xnumeric
pi_FS-Xnumeric
pi_SB-Xnumeric
pi_SI-Xnumeric
pi_SL-Xnumeric
pi_CH-Znumeric
pi_CU-Znumeric
pi_FA-Znumeric
pi_FC-Znumeric
pi_FS-Znumeric
pi_SB-Znumeric
pi_SI-Znumeric
pi_SL-Znumeric
pi_wCHnumeric
pi_wCUnumeric
pi_wFAnumeric
pi_wFCnumeric
pi_wFSnumeric
pi_wSBnumeric
pi_wSInumeric
pi_wSLnumeric
pi_wCH_Cnumeric
pi_wCU_Cnumeric
pi_wFA_Cnumeric
pi_wFC_Cnumeric
pi_wFS_Cnumeric
pi_wSB_Cnumeric
pi_wSI_Cnumeric
pi_wSL_Cnumeric
pi_O-Swing_pctnumeric
pi_Z-Swing_pctnumeric
pi_Swing_pctnumeric
pi_O-Contact_pctnumeric
pi_Z-Contact_pctnumeric
pi_Contact_pctnumeric
pi_Zone_pctnumeric
pi_Pacenumeric
Eventsinteger
EVnumeric
LAnumeric
Barrelsinteger
Barrel_pctnumeric
maxEVnumeric
HardHitinteger
HardHit_pctnumeric
Qnumeric
TGinteger
TPAinteger
team_name_abbcharacter
teamidinteger
Posnumeric
phLInumeric
pi_XX_pctnumeric
pi_vXXnumeric
pi_XX-Xnumeric
pi_XX-Znumeric
pi_wXXnumeric
pi_wXX_Cnumeric
rBTVnumeric
pi_CS_pctnumeric
pi_vCSnumeric
pi_CS-Xnumeric
pi_CS-Znumeric
pi_wCSnumeric
pi_wCS_Cnumeric
KN_pctnumeric
KNvnumeric
wKNnumeric
wKN_Cnumeric
pfx_KN_pctnumeric
pfx_vKNnumeric
pfx_KN-Xnumeric
pfx_KN-Znumeric
pfx_wKNnumeric
pfx_wKN_Cnumeric
pi_KN_pctnumeric
pi_vKNnumeric
pi_KN-Xnumeric
pi_KN-Znumeric
pi_wKNnumeric
pi_wKN_Cnumeric
rCPTVnumeric
CFramingnumeric
rDGVnumeric
rDSVnumeric

Arguments

age

(integer) Age of players

pos

(character) Position of players, defaults to "all". To exclude pitchers, use "np".

stats

(character) Statistic to return. Defaults to "bat".

lg

(character) League to return. Defaults to "all". Options are "al", "nl", or "all".

qual

(character) Whether you want only batters/pitchers that qualified in a given season, or the minimum number of plate appearances for inclusion. If you only want qualified hitters, use qual. If a minimum number of plate appearaces/innings pitched, use the number desired. Defaults to "y".

startseason

(character) Season for which you want to scrape the data.

endseason

(character) Last season for which you want data.

startdate

(character) Start date for which you want data.

enddate

(character) End date for which you want data.

month

(character) Month for which you want data.

hand

(character) Handedness of batter. Options are "L", "R", or "B". Empty string returns all.

team

(character) Teams for which you want data, comma separated.

pageitems

(character) Number of items per page.

pagenum

(character) Page number.

ind

(character) Whether or not to break the seasons out individual, or roll them up together. 1 = split seasons, 0 = aggregate seasons.

rost

(character) Whether or not to include players on the roster. 1 = include, 0 = exclude.

players

(character) Whether or not to include players on the roster. 1 = include only active roster players, 0 = exclude.

type

(character) Defaults to 8, which is the standard leaderboard. The values for the leaderboards appear to go to from type = 0 to 48+, which correspond to links on the leaderboard page.

postseason

(logical) Whether or not to include postseason data. TRUE = include postseason, FALSE = exclude postseason.

sortdir

(character) Sort direction. Options are "asc" or "desc" or "default".

sortstat

(character) Sort by stat. Default is "WAR".

Examples

Run this code
# \donttest{
  try(fg_batter_leaders(startseason = 2023, endseason = 2023))
# }

Run the code above in your browser using DataLab