Skip to content

Instantly share code, notes, and snippets.

@Rharald
Rharald / EP2012_1.R
Created November 17, 2012 06:34
EP2012
## harald, 2012-11-11
# this script downloads all exit polls for the U.S. presidential
# election on 2012-11-06 from CNN and saves the resulting
# data.frame to file
# for later puropses it can be loaded by
# load(file="PresExitPolls2012.Rdata")
library(XML)
library(plyr)
source("getStateData.R")
@Rharald
Rharald / snippet1.R
Created November 16, 2012 04:48
Vote by Age
unique(EP$QNo[EP$question=="Vote by Age"])
# 4 category breakdown
head(EP[EP$QNo==2, ])
# 6 category breakdown
head(EP[EP$QNo==3, ])
@Rharald
Rharald / crosshairs2.R
Created November 9, 2012 05:02
crosshairs2.R
# numbers from http://news.cnet.com/8301-13578_3-57546778-38/among-the-top-election-quants-nate-silver-reigns-supreme/
nate <- c(50.8, 48.3)
tpm <- c(48.8, 48.1)
rcp <- c(48.8, 48.1)
huff <- c(48.1, 46.7)
png('crosshairs2.png')
crosshairs(centre = centre, # the actual popular vote
pts = pts, # the predistions
no.rings = 4, # four rings seem about right here ("4 more years")
title = "Pollsters on target?",
@Rharald
Rharald / gist:4040423
Created November 8, 2012 18:00
crosshairs.R
## harald, 2012-11-08
# make crosshairs plot for pollster precision
# this version prepared for the blogpost
# on http://adistantobserver.blogspot.de/2012/11/pebos-post-election-burn-out-syndrome.html
# first a helper function for downloading the necessary data
getTablesFromURL <- function (URI, index = integer(), header = FALSE) {
require(RCurl)
require(XML)
result <- getURLContent(URI, useragent = "RCurl")