Skip to content

Instantly share code, notes, and snippets.

@peterhurford
peterhurford / r-interview.md
Last active January 12, 2022 21:55
R Interview Questions

1.) If I have a data.frame df <- data.frame(a = c(1, 2, 3), b = c(4, 5, 6), c(7, 8, 9))...

1a.) How do I select the c(4, 5, 6)?

1b.) How do I select the 1?

1c.) How do I select the 5?

1d.) What is df[, 3]?

@craigmbooth
craigmbooth / teams.txt
Created October 15, 2013 16:53
List of NFL teams, host cities and names for use by the iPython notebook that scrapes the web for player heights and weights.
ATL - Atlanta - FALCONS
BUF - Buffalo - BILLS
CHI - Chicago - BEARS
CIN - Cincinnati - BENGALS
CLE - Cleveland - BROWNS
BAL - Baltimore - RAVENS
DAL - Dallas - COWBOYS
DEN - Denver - BRONCOS
DET - Detroit - LIONS
GB - Green Bay - PACKERS
@isaactpetersen
isaactpetersen / FantasyPros projections
Last active December 15, 2021 15:19
FantasyPros projections
#Load libraries
library("XML")
#Download fantasy football projections from FantasyPros.com
qb_fp <- readHTMLTable("http://www.fantasypros.com/nfl/projections/qb.php", stringsAsFactors = FALSE)$data
rb_fp <- readHTMLTable("http://www.fantasypros.com/nfl/projections/rb.php", stringsAsFactors = FALSE)$data
wr_fp <- readHTMLTable("http://www.fantasypros.com/nfl/projections/wr.php", stringsAsFactors = FALSE)$data
te_fp <- readHTMLTable("http://www.fantasypros.com/nfl/projections/te.php", stringsAsFactors = FALSE)$data
@ramhiser
ramhiser / download-espn-mlb-standings.py
Last active December 15, 2016 12:51
Python script to scrape ESPN for American League standings by team.
# The following script scrapes ESPN's MLB Standings Grid and writes the
# standings for each American League (AL) team to a CSV file, which has the following
# format:
# Team, Opponent, Wins, Losses
from bs4 import BeautifulSoup
import urllib2
import re
import csv
@Protonk
Protonk / ivest.R
Created March 29, 2011 22:12
Very simple (and flawed) IV estimation
library(AER)
library(lmtest)
data("CollegeDistance")
cd.d<-CollegeDistance
simple.ed.1s<- lm(education ~ distance,data=cd.d)
cd.d$ed.pred<- predict(simple.ed.1s)
simple.ed.2s<- lm(wage ~ urban + gender + ethnicity + unemp + ed.pred , data=cd.d)
simple.comp<- encomptest(wage ~ urban + gender + ethnicity + unemp + ed.pred , wage ~ urban + gender + ethnicity + unemp + education , data=cd.d)
1s.ftest<- encomptest(education ~ tuition + gender + ethnicity + urban , education ~ distance , data=cd.d)