Downloading NFL.com Fantasy Football Projections using R

March 9, 2013
By

(This article was first published on Fantasy Football Analytics in R, and kindly contributed to R-bloggers)

In this post, I will show how to download NFL.com fantasy football projections using R.

The R Script

The R Script for downloading fantasy football projections from NFL.com is located at: https://github.com/dadrivr/FantasyFootballAnalyticsR/blob/master/R%20Scripts/NFL%20Projections.R
#Download fantasy football projections from NFL.com
qb1_nfl <- readHTMLTable("http://fantasy.nfl.com/research/projections?position=1&sort=projectedPts&statCategory=projectedStats&statSeason=2012&statType=seasonProjectedStats", stringsAsFactors = FALSE)$`NULL`
qb2_nfl <- readHTMLTable("http://fantasy.nfl.com/research/projections?offset=26&position=1&sort=projectedPts&statCategory=projectedStats&statSeason=2012&statType=seasonProjectedStats", stringsAsFactors = FALSE)$`NULL`
rb1_nfl <- readHTMLTable("http://fantasy.nfl.com/research/projections?position=2&statCategory=projectedStats&statSeason=2012&statType=seasonProjectedStats", stringsAsFactors = FALSE)$`NULL`
rb2_nfl <- readHTMLTable("http://fantasy.nfl.com/research/projections?offset=26&position=2&sort=projectedPts&statCategory=projectedStats&statSeason=2012&statType=seasonProjectedStats", stringsAsFactors = FALSE)$`NULL`
rb3_nfl <- readHTMLTable("http://fantasy.nfl.com/research/projections?offset=51&position=2&sort=projectedPts&statCategory=projectedStats&statSeason=2012&statType=seasonProjectedStats", stringsAsFactors = FALSE)$`NULL`
wr1_nfl <- readHTMLTable("http://fantasy.nfl.com/research/projections?position=3&sort=projectedPts&statCategory=projectedStats&statSeason=2012&statType=seasonProjectedStats", stringsAsFactors = FALSE)$`NULL`
wr2_nfl <- readHTMLTable("http://fantasy.nfl.com/research/projections?offset=26&position=3&sort=projectedPts&statCategory=projectedStats&statSeason=2012&statType=seasonProjectedStats", stringsAsFactors = FALSE)$`NULL`
wr3_nfl <- readHTMLTable("http://fantasy.nfl.com/research/projections?offset=51&position=3&sort=projectedPts&statCategory=projectedStats&statSeason=2012&statType=seasonProjectedStats", stringsAsFactors = FALSE)$`NULL`
te_nfl <- readHTMLTable("http://fantasy.nfl.com/research/projections?position=4&statCategory=projectedStats&statSeason=2012&statType=seasonProjectedStats", stringsAsFactors = FALSE)$`NULL`

Here’s a density plot of the NFL.com projections:

ggplot(projections_nfl, aes(x=pts_nfl), fill=pos) + geom_density(fill="green", alpha=.3) + xlab("Player's Projected Points") + ggtitle("Density Plot of NFL.com Projected Points from 2012")

To leave a comment for the author, please follow the link and comment on their blog: Fantasy Football Analytics in R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)