Site icon R-bloggers

The NFL Reloads: Using R to Have a Look

[This article was first published on Fear and Loathing in Data Science, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

NFL Draft 2014

It can’t be easy being a Jacksonville Jaguars fan. It seems that management has learned nothing from the Blaine Gabbert debacle. By that I mean I’m not impressed with their first round pick Blake Bortles. Bucky Brooks of NFL.com called him a “developmental prospect”. Developmental? Is that what you want from the third overall pick? I hate to say it but I have to agree with Skip Bayless that Bortles is the new Gabbert in J-Ville. We shall see soon enough if I will eat these words!
At any rate, I’ve downloaded draft data from the web and you can explore the draft at your own leisure. I scrapped it off of wikipedia at this link: http://en.wikipedia.org/wiki/2014_NFL_Draft
I put together some code to get you on your way to exploring

attach(nfldraft)
str(nfldraft)
## 'data.frame':    256 obs. of  8 variables:
##  $ round     : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ pick      : int  1 2 3 4 5 6 7 8 9 10 ...
##  $ team      : Factor w/ 32 levels "Arizona Cardinals",..: 13 29 15 4 23 2 30 8 18 11 ...
##  $ player    : Factor w/ 256 levels "Aaron Colvin ",..: 96 89 25 204 147 97 178 131 12 84 ...
##  $ position  : Factor w/ 18 levels "C","CB","DE",..: 3 11 13 18 9 11 18 2 9 17 ...
##  $ college   : Factor w/ 113 levels "Alabama","Arizona",..: 86 6 99 15 12 95 95 71 100 62 ...
##  $ conference: Factor w/ 24 levels "ACC","Big 12",..: 21 21 24 1 11 21 21 2 17 1 ...
##  $ notes     : Factor w/ 88 levels "","from Arizona[R1 - 5]",..: 1 86 1 20 1 1 1 51 9 1 ...
names(nfldraft)
## [1] "round"      "pick"       "team"       "player"     "position"  
## [6] "college"    "conference" "notes"
mytable = table(position, round)  #create a table of player position and round 
selected
mytable
##         round
## position 1 2 3 4 5 6 7
##      C   0 1 2 2 2 2 1
##      CB  5 1 2 9 4 7 5
##      DE  2 3 3 2 5 3 4
##      DT  2 3 4 3 3 1 4
##      FB  0 0 0 0 0 1 1
##      FS  0 0 0 0 0 0 2
##      G   0 1 6 1 4 2 0
##      K   0 0 0 0 0 0 2
##      LB  5 3 3 5 6 2 7
##      OLB 0 0 0 0 2 1 0
##      OT  5 4 3 1 1 3 4
##      P   0 0 0 0 0 1 0
##      QB  3 2 0 2 2 5 0
##      RB  0 3 5 5 0 4 2
##      S   4 1 2 4 3 1 0
##      SS  0 0 0 0 0 1 2
##      TE  1 3 3 0 1 0 2
##      WR  5 7 3 6 3 5 5
margin.table(mytable)  #generic table with sum...not very useful
## [1] 256
margin.table(mytable, 1)  #sum of positions selected
## position
##   C  CB  DE  DT  FB  FS   G   K  LB OLB  OT   P  QB  RB   S  SS  TE  WR 
##  10  33  22  20   2   2  14   2  31   3  21   1  14  19  15   3  10  34


margin.table(mytable, 2)  #sum of players selected by round
## round
##  1  2  3  4  5  6  7 
## 32 32 36 40 36 39 41


mosaicplot(mytable, main = "Position by Round", xlab = "Position", 
ylab = "Round", cex.axis = 1)  #you can use mosaicplot to graphically 
represent the data in the table













What if you want to drill-down on a specific team or the like? Here is some simple code to examine a specific team, in this case the Colts:
colts = nfldraft[which(nfldraft$team == "Indianapolis Colts"), ]  #select the 
rows of data unique to the Colts
colts.table = table(colts$round, colts$position)


margin.table(colts.table, 2)
## 
##   C  CB  DE  DT  FB  FS   G   K  LB OLB  OT   P  QB  RB   S  SS  TE  WR 
##   0   0   1   0   0   0   0   0   1   0   2   0   0   0   0   0   0   1


barplot(colts.table)













There you have it. With some quick modifications to the above, you could produce tables examining players selected by conference, college etc.

To leave a comment for the author, please follow the link and comment on their blog: Fear and Loathing in Data Science.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.