Learn R Programming

baseballr (version 1.5.0)

run_expectancy_code: Generate run expectancy and related measures from Baseball Savant data

Description

These functions allow a user to generate run expectancy and related measures and variables from Baseball Savant data. Measures and variables will be added to the data frame.

Usage

run_expectancy_code(df, level = "plate appearance")

Value

Returns a tibble with the following columns:

col_nametypes
pitch_typecharacter
game_dateDate
release_speednumeric
release_pos_xnumeric
release_pos_znumeric
player_namecharacter
batternumeric
pitchernumeric
eventscharacter
descriptioncharacter
spin_dirlogical
spin_rate_deprecatedlogical
break_angle_deprecatedlogical
break_length_deprecatedlogical
zonenumeric
descharacter
game_typecharacter
standcharacter
p_throwscharacter
home_teamcharacter
away_teamcharacter
typecharacter
hit_locationinteger
bb_typecharacter
ballsinteger
strikesinteger
game_yearinteger
pfx_xnumeric
pfx_znumeric
plate_xnumeric
plate_znumeric
on_3bnumeric
on_2bnumeric
on_1bnumeric
outs_when_upinteger
inningnumeric
inning_topbotcharacter
hc_xnumeric
hc_ynumeric
tfs_deprecatedlogical
tfs_zulu_deprecatedlogical
fielder_2numeric
umpirelogical
sv_idcharacter
vx0numeric
vy0numeric
vz0numeric
axnumeric
aynumeric
aznumeric
sz_topnumeric
sz_botnumeric
hit_distance_scnumeric
launch_speednumeric
launch_anglenumeric
effective_speednumeric
release_spin_ratenumeric
release_extensionnumeric
game_pknumeric
pitcher_1numeric
fielder_2_1numeric
fielder_3numeric
fielder_4numeric
fielder_5numeric
fielder_6numeric
fielder_7numeric
fielder_8numeric
fielder_9numeric
release_pos_ynumeric
estimated_ba_using_speedanglenumeric
estimated_woba_using_speedanglenumeric
woba_valuenumeric
woba_denominteger
babip_valueinteger
iso_valueinteger
launch_speed_angleinteger
at_bat_numbernumeric
pitch_numbernumeric
pitch_namecharacter
home_scorenumeric
away_scorenumeric
bat_scorenumeric
fld_scorenumeric
post_away_scorenumeric
post_home_scorenumeric
post_bat_scorenumeric
post_fld_scorenumeric
if_fielding_alignmentcharacter
of_fielding_alignmentcharacter
spin_axisnumeric
delta_home_win_expnumeric
delta_run_expnumeric
final_pitch_gamenumeric
final_pitch_at_batnumeric
runs_scored_on_pitchnumeric
bat_score_afternumeric
final_pitch_inningnumeric
bat_score_start_inningnumeric
bat_score_end_inningnumeric
cum_runs_in_inningnumeric
runs_to_end_inningnumeric
count_base_out_statecharacter
avg_renumeric
next_count_base_out_statecharacter
next_avg_renumeric
change_renumeric
re24numeric

Arguments

df

A data frame generated from Baseball Savant.

level

Whether you want run expectancy calculated at the plate appearance or pitch level. Defaults to plate appearance.

Examples

Run this code
# \donttest{
  df <- statcast_search(start_date = "2016-04-06", end_date = "2016-04-15", 
                        playerid = 621043, player_type = 'batter') 
  try(run_expectancy_code(df, level = "plate appearances"))
# }

Run the code above in your browser using DataLab