lecy / foundations-of-data-science-for-the-public-sector

Lecture notes and labs for an introductory data science course for public policy and nonprofit management students
1 stars 0 forks source link

lab 6 calculate the league average #6

Open pkshen opened 6 years ago

pkshen commented 6 years ago

In lab 6 question 3, how to calculate the league average? I thought is league average=R/G, is that correct?

lecy commented 6 years ago

You will create a new variable for average strike-outs per game. This is calculated at the team level.

ave.so <- Teams$SO / Teams$G

Then to calculate the league average over time, you will need to average all of the new ave.so variables by year. You can either use tapply() or group_by() plus summarize() to calculate the average league stats by year.