Skip to content

Instantly share code, notes, and snippets.

@tcash21
Created February 2, 2013 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcash21/4698356 to your computer and use it in GitHub Desktop.
Save tcash21/4698356 to your computer and use it in GitHub Desktop.
setwd("R/")
setwd("NFL Play-by-Play Data 2002-2012/")
## read in the sweet, sweet NFL data
seasons <- c(2002:2011)
n <- read.csv("2012_nfl_pbp_data_reg_season.csv", header=TRUE, stringsAsFactors=FALSE)
n1 <- read.csv("2002_nfl_pbp_data.csv", header=TRUE, stringsAsFactors=FALSE)
n <- n[,-which(is.na(match(colnames(n), colnames(n1))))]
for(i in seasons){
n1 <- read.csv(paste(i, "_nfl_pbp_data.csv", sep=""), header=TRUE, stringsAsFactors=FALSE)
n <- rbind(n, n1)
}
## grab the no huddle plays
nh <- n[grep("Huddle", n$description),]
## grab every other play
h <- n[-grep("Huddle", n$description),]
## calculate the percentage of no-huddle plays each team ran by season
hvsnh.by.season <- data.frame(table(nh$off, nh$season) / (table(nh$off, nh$season) + table(h$off, h$season)))[-1,]
## write out for Tableau
write.table(hvsnh.by.season, file="hvsnh.txt", sep="\t", row.names=FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment