Created
October 10, 2016 00:52
-
-
Save seanjtaylor/909f5643f7d5e5409f56e7c18857a29e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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