Skip to contents

Build columns that aggregate official defense stats either at the game level or at the level of the entire data frame passed.

Usage

calculate_player_stats_def(pbp, weekly = FALSE)

Arguments

pbp

A Data frame of NFL play-by-play data typically loaded with load_pbp() or build_nflfastR_pbp(). If the data doesn't include the variable qb_epa, the function add_qb_epa() will be called to add it.

weekly

If TRUE, returns week-by-week stats, otherwise, stats for the entire Data frame.

Value

A data frame of defensive player stats. See dictionary (# TODO)

See also

The function load_player_stats() and the corresponding examples on the nflfastR website

Examples

# \donttest{
try({# to avoid CRAN test problems
  pbp <- nflfastR::load_pbp(2020)

  weekly <- calculate_player_stats_def(pbp, weekly = TRUE)
  dplyr::glimpse(weekly)

  overall <- calculate_player_stats_def(pbp, weekly = FALSE)
  dplyr::glimpse(overall)
})
#> Rows: 9,275
#> Columns: 32
#> $ season                        <int> 2020, 2020, 2020, 2020, 2020, 2020, 2020…
#> $ week                          <int> 3, 11, 3, 5, 11, 12, 15, 6, 10, 12, 15, …
#> $ season_type                   <chr> "REG", "REG", "REG", "REG", "REG", "REG"…
#> $ player_id                     <chr> "00-0022921", "00-0022924", "00-0023448"…
#> $ player_name                   <chr> "L.Fitzgerald", "B.Roethlisberger", "T.D…
#> $ player_display_name           <chr> "Larry Fitzgerald", "Ben Roethlisberger"…
#> $ position                      <chr> "WR", "QB", "OLB", "OLB", "OLB", "OLB", …
#> $ position_group                <chr> "WR", "QB", "LB", "LB", "LB", "LB", "LB"…
#> $ headshot_url                  <chr> "https://static.www.nfl.com/image/privat…
#> $ team                          <chr> "DET", "JAX", "WAS", "WAS", "WAS", "WAS"…
#> $ def_tackles                   <int> 1, 1, 2, 0, 1, 2, 0, 1, 1, 3, 3, 3, 2, 2…
#> $ def_tackles_solo              <int> 1, 1, 2, 0, 1, 2, 0, 1, 1, 3, 3, 3, 2, 2…
#> $ def_tackles_with_assist       <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_tackle_assists            <int> 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0…
#> $ def_tackles_for_loss          <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_tackles_for_loss_yards    <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_fumbles_forced            <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_sacks                     <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_sack_yards                <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_qb_hits                   <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0…
#> $ def_interceptions             <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_interception_yards        <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_pass_defended             <dbl> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0…
#> $ def_tds                       <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_fumbles                   <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_fumble_recovery_own       <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_fumble_recovery_yards_own <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_fumble_recovery_opp       <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_fumble_recovery_yards_opp <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_safety                    <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_penalty                   <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_penalty_yards             <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> Rows: 1,418
#> Columns: 30
#> $ player_id                     <chr> "00-0022921", "00-0022924", "00-0023448"…
#> $ player_name                   <chr> "L.Fitzgerald", "B.Roethlisberger", "T.D…
#> $ player_display_name           <chr> "Larry Fitzgerald", "Ben Roethlisberger"…
#> $ games                         <int> 1, 1, 5, 1, 5, 3, 7, 6, 1, 1, 13, 1, 5, …
#> $ position                      <chr> "WR", "QB", "OLB", "QB", "CB", "CB", "CB…
#> $ position_group                <chr> "WR", "QB", "LB", "QB", "DB", "DB", "DB"…
#> $ headshot_url                  <chr> "https://static.www.nfl.com/image/privat…
#> $ team                          <chr> "DET", "JAX", "WAS", "NYJ", "BAL", "ARI"…
#> $ def_tackles                   <int> 1, 1, 5, 1, 12, 3, 25, 6, 1, 1, 19, 1, 8…
#> $ def_tackles_solo              <int> 1, 1, 5, 1, 12, 2, 23, 6, 1, 1, 16, 1, 6…
#> $ def_tackles_with_assist       <int> 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 3, 0, 2, 2…
#> $ def_tackle_assists            <int> 0, 0, 1, 0, 4, 0, 4, 10, 0, 0, 13, 0, 6,…
#> $ def_tackles_for_loss          <int> 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 2…
#> $ def_tackles_for_loss_yards    <dbl> 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0, 4…
#> $ def_fumbles_forced            <int> 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0…
#> $ def_sacks                     <dbl> 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, …
#> $ def_sack_yards                <dbl> 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, …
#> $ def_qb_hits                   <dbl> 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 11, 0, 0, …
#> $ def_interceptions             <dbl> 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0…
#> $ def_interception_yards        <dbl> 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0…
#> $ def_pass_defended             <dbl> 0, 0, 1, 0, 1, 1, 5, 0, 0, 0, 7, 0, 0, 0…
#> $ def_tds                       <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_fumbles                   <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_fumble_recovery_own       <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_fumble_recovery_yards_own <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_fumble_recovery_opp       <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_fumble_recovery_yards_opp <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_safety                    <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
#> $ def_penalty                   <dbl> 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 1, 1, 1…
#> $ def_penalty_yards             <dbl> 0, 0, 0, 0, 0, 0, 22, 0, 0, 0, 25, 14, 1…
# }