Skip to content

Instantly share code, notes, and snippets.

@seanjtaylor
Created October 10, 2016 00:52
Show Gist options
  • Save seanjtaylor/909f5643f7d5e5409f56e7c18857a29e to your computer and use it in GitHub Desktop.
Save seanjtaylor/909f5643f7d5e5409f56e7c18857a29e to your computer and use it in GitHub Desktop.
library(rvest)
library(dplyr)
html.doc <- read_html('http://www.footballoutsiders.com/stat-analysis/2016/quarterbacks-and-progression-air-yards')
# Extract table
raw.table <- html.doc %>%
html_table() %>%
first
# Get the actual table
my.data <- raw.table %>% tail(-2)
# Set the column names
colnames(my.data) <- raw.table[2,]
# Clean up the table and convert to long format.
cleaned <- my.data %>%
gather(year, air.yards, -Quarterback) %>%
filter(year != 'AVG', air.yards != '-') %>%
mutate(year = as.numeric(year),
air.yards = as.numeric(air.yards))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment