bcongelio / nfl-analytics-with-r-book

The repo for Introduction to NFL Analytics with R (published with CRC Press)
https://bradcongelio.com/nfl-analytics-with-r-book/
Creative Commons Zero v1.0 Universal
51 stars 15 forks source link

Error in Group By #9

Closed Timboslice003 closed 11 months ago

Timboslice003 commented 11 months ago

Hello, for section 3.5.12 I think there is an issue with this section:

dakota_composite <- nflreadr::load_player_stats(2022) %>% filter(position == "QB") %>% group_by(player_display_name, season) %>% summarize(attempts = sum(attempts, na.rm = TRUE), mean_dakota = mean(dakota, na.rm = TRUE)) %>% filter(attempts >= 200)

This caused the resulting plot to have a lot more points than the example given. Once I removed season from the group by it worked as expected.

**Update: Nevermind I was doing something wrong.

bcongelio commented 11 months ago

I am glad you figured it out.

For reference (in case somebody else runs across this), adding season to the group_by() typically is not needed. However, because this example is being merged with information from the load_contracts() function, we include the season in order to join the information to each player by the associated year.