0

I am using NFL play-by-play data from the 2013 season and I am looking to measure catch success rate by Wide Receivers. Essentially, I have four variables of interest: Targeted Receiver, Pass Distance, Target and Reception. I would like to obtain a data set broken down by Targeted Receiver and Pass Distance, with Targets and Receptions summarized (just a simple count) for each of the two Targeted Receiver and Pass Distance combinations (i.e. Receiver 1 Short, Receiver 1 Long).

Thank you for your help,

CLR

CLR
  • 1
  • What did you try? Why did it not work? – Heroka Mar 22 '16 at 17:01
  • 1
    Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Mar 22 '16 at 17:15

1 Answers1

0

First, take the table df and keep only the columns that are relevant (Targeted Receiver, Pass Distance, Target, and Reception).

df <- select(df, `Targeted Receiver`, `Pass Distance`, `Target`, `Reception`)

Then, remove the rows where there is no receiver (e.g. a running play).

df <- df[!is.na(df$`Targeted Receiver`), ]

After that, use group_by from dplyr so that your data are grouped at the Target Receiver and Pass Distance level.

grouped <- group_by(df, `Targeted Receiver`, `Pass Distance`)

Finally, use the summarise function to create the count of Target and the sum of Reception.

per_rec <- summarise(grouped, Target = n(), Reception = sum(Reception))

The data will look like this:

  Targeted Receiver Pass Distance Target Reception
              (chr)         (chr)  (int)     (dbl)
1        A.J. Green          Deep     50        21
2        A.J. Green         Short    128        77
3      A.J. Jenkins          Deep      6         2
4      A.J. Jenkins         Short     11         6
5      Aaron Dobson          Deep     23         6
6      Aaron Dobson         Short     49        31
cpander
  • 374
  • 2
  • 9
  • Please elaborate on how this code answers the question (this answer was in the Low Quality Posts review queue). – JAL Mar 22 '16 at 20:06