Get Official Game Stats on Defense
Source:R/aggregate_game_stats_def.R
calculate_player_stats_def.Rd
Build columns that aggregate official defense stats either at the game level or at the level of the entire data frame passed.
Arguments
- pbp
A Data frame of NFL play-by-play data typically loaded with
load_pbp()
orbuild_nflfastR_pbp()
. If the data doesn't include the variableqb_epa
, the functionadd_qb_epa()
will be called to add it.- weekly
If
TRUE
, returns week-by-week stats, otherwise, stats for the entire Data frame.
See also
The function load_player_stats()
and the corresponding examples
on the nflfastR website
Examples
# \donttest{
pbp <- nflfastR::load_pbp(2020)
weekly <- calculate_player_stats_def(pbp, weekly = TRUE)
dplyr::glimpse(weekly)
#> Rows: 9,275
#> Columns: 31
#> $ season <int> 2020, 2020, 2020, 2020, 2020, 2020, 2020…
#> $ week <int> 3, 11, 3, 5, 11, 12, 15, 6, 10, 12, 15, …
#> $ 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…
overall <- calculate_player_stats_def(pbp, weekly = FALSE)
dplyr::glimpse(overall)
#> Rows: 1,418
#> Columns: 30
#> $ player_id <chr> "00-0022921", "00-0022924", "00-0023448"…
#> $ team <chr> "DET", "JAX", "WAS", "NYJ", "BAL", "ARI"…
#> $ 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…
#> $ 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_hit <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…
# }