R/sch_code_barrel.R

Defines functions code_barrel

Documented in code_barrel

#' @title **Helper for determining whether a batted ball is a "barrel"**
#'
#' @description This function allows you to code a batted ball as a barrel as defined by the Statcast research team using data as provided by baseballsavant.mlb.com.
#' @param df A dataframe generated by baseballsavant.mlb.com that must include the following variables: `launch_angle` and `launch_speed`.
#' @return Returns a tibble with the additional column, `barrel`.
#' @export

code_barrel <- function(df) {
  df$barrel <- with(df, ifelse(launch_angle <= 50 & launch_speed >= 98 & launch_speed * 1.5 - 
                                 launch_angle >= 117 & launch_speed + launch_angle >= 124, 1, 0))
  return(df)
}

Try the baseballr package in your browser

Any scripts or data that you put into this service are public.

baseballr documentation built on April 1, 2023, 12:12 a.m.