Skip to content

Commit 7d53e07

Browse files
authored
Merge pull request #505 from nflverse/seasonlvl-targetshare-airyardshare
2 parents 363344d + 2308d30 commit 7d53e07

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: nflfastR
33
Title: Functions to Efficiently Access NFL Play by Play Data
4-
Version: 5.0.0.9001
4+
Version: 5.0.0.9002
55
Authors@R:
66
c(person(given = "Sebastian",
77
family = "Carl",

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Fixed a bug where `calculate_stats()` incorrectly counted `receiving_air_yards`. (#500)
44
- Fixed a bug where `vegas_wp` variables were broken when `spread_line` data was missing. (#503)
5+
- Fixed a bug where `calculate_stats()` incorrectly calculated `target_share` and `air_yards_share` when `summary_level = "season"`. (#505)
56

67
# nflfastR 5.0.0
78

R/calculate_stats.R

+6-2
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,13 @@ calculate_stats <- function(seasons = nflreadr::most_recent_season(),
122122
team_stats = paste0(paste(stat_id, collapse = ";"), ";"),
123123
team_play_air_yards = sum((stat_id %in% 111:112) * yards)
124124
) %>%
125-
dplyr::group_by(.data$season, .data$week, .data$team) %>%
125+
# compute team targets and team air yards for calculation of target share
126+
# and air yard share. Since it's relative, we need to be careful with the groups
127+
# depending on summary level
128+
dplyr::group_by(!!!rlang::data_syms(
129+
if (summary_level == "season") c("season", "team") else c("season", "week", "team")
130+
)) %>%
126131
dplyr::mutate(
127-
# for calculation of target share and air yard share
128132
team_targets = sum(stat_id == 115),
129133
team_air_yards = sum((stat_id %in% 111:112) * yards)
130134
) %>%

0 commit comments

Comments
 (0)