Skip to content

Instantly share code, notes, and snippets.

View christophergandrud's full-sized avatar

Christopher Gandrud christophergandrud

View GitHub Profile
@christophergandrud
christophergandrud / gist:1284498
Last active September 27, 2015 14:28
Simple Web Crawler for Text
# Load RCurl package
library(RCurl)
addresses <- read.csv("~/links.csv") # Create a .csv file with all of the links you want to crawl
for (i in addresses) full.text <- getURL(i)
text.sub <- gsub("<.+?>", "", full.text) # Removes HTML tags
text <- data.frame(text.sub)
@christophergandrud
christophergandrud / gist:1287427
Created October 14, 2011 15:26
Google Motion Chart of World Bank External Debt Data
# Create Google Motion Chart from World Bank Finance Data
# Inspired by http://lamages.blogspot.com/2011/09/accessing-and-plotting-world-bank-data.html
# Written by Christopher Gandrud
# 15 October 2011
library(WDI)
library(gregmisc)
library(googleVis)
@christophergandrud
christophergandrud / partisan_graph_Gandrud.R
Created December 22, 2011 08:47
Partisan Inflation Forecast Error Graph
################
# Partisan Inflation Forecast Error Graph
# Christopher Gandrud
# Updated 22 December 2011
################
library(foreign)
library(ggplot2)
## Load data
@christophergandrud
christophergandrud / get_fed_speeches.R
Created December 26, 2011 07:11
Gather Fed Speeches
## Download websites
addresses <- read.csv("~/links.full.csv")
for (i in addresses){
fed.text <- getURL(i)
}
fed.df <- as.data.frame(fed.text)
@christophergandrud
christophergandrud / fed.speeches.parse.R
Created December 26, 2011 07:50
Parse Fed speeches HTML files
#######################
## Open text files, parse individually and remove text of the the speeches
setwd("~/fed.text.indv/")
# Create list of text files to parse and extract speech text from
files <- list.files(path = "~/fed.text.indv/", pattern = "*.txt")
# Create object to record empty text files (likely empty due to error in the website download)
missing <- NULL
@christophergandrud
christophergandrud / fed.speeches.save.subset.R
Created December 26, 2011 08:12
Save Fed Speeches for a Subset
## Save raw HTML to individual text files for a subset
# Create id numbers that matches the full list of URLS
# This included URLs numbered 490 to 625
fed.subset.df$id <- c(490:625)
y <- 1:nrow(fed.subset.df)
## Save Subset of HTML files
for(i in y) {
@christophergandrud
christophergandrud / japan_US_gdp_comparision.R
Created December 29, 2011 04:04
Japan US gdp change comparison graph
##############################
# Create a Google Line Graph to Compare the Difference between Japanese & US GDP Growth using Data
# from the World Bank
# Christopher Gandrud
# Updated 29 December 2011
##############################
library(WDI)
library(gregmisc)
library(googleVis)
@christophergandrud
christophergandrud / leg.violence.map.R
Last active September 29, 2015 03:07
Legislative Violence Map
########################
# Map of incidences of legislative violence (1980-2011)
# Christopher Gandrud
# Updated 6 September 2013
########################
library(foreign)
library(googleVis)
library(gregmisc)
library(plyr)
@christophergandrud
christophergandrud / fed.forecast.time.series.R
Created February 7, 2012 09:22
Fed Forecast Errors Time Series Graph
########
# Fed Inflation Forecast Error Times Series Graph
# Christopher Gandrud
# Updated 7 January 2011
########
### Using data frame cpi.data
#### Clean up data and create forecast error variable
cpi.data$pres_party <- factor(cpi.data$pres_party, label = c("Dem", "Rep"))
@christophergandrud
christophergandrud / disprop_map_chart.R
Created March 25, 2012 09:05
Disproportionality Map and Chart
############
# Gallagher Disproportionality Data Explore
# Christopher Gandrud
# 25 March 2012
###########
library(foreign)
library(ggplot2)
library(googleVis)
library(gdata)