Skip to content

Instantly share code, notes, and snippets.

users<-c("screenname1", "screenname2", "screenname3")
out<-NULL
for (i in 1:length(users)){
user<-users[i]
friends <- tryCatch(getFriends(screen_name=user, oauth="~/Dropbox/credentials/twitter"),
error=function(error_message) {
message(error_message)
return(NA)
@jmrphy
jmrphy / uk_social_attitudes_survey_2011.r
Last active December 2, 2016 11:55
UK Social Attitudes 2011 starter script
require(foreign)
### Define the URL where the dataset (.csv) is located
url<-"https://dl.dropboxusercontent.com/u/20498362/uk_social_attitudes_survey_2011/uk_social_attitudes_survey_2011.csv?raw=1"
### Read in the data from the url we just defined, call it "data"
data <- read.csv(url)
### Some Generic variables
@jmrphy
jmrphy / uk_health_survey_2011.r
Created February 18, 2014 17:40
UK Health Survey 2011 starter script
### Define the URL where the dataset is located
url<-"http://dl.dropboxusercontent.com/u/20498362/uk_health_survey_2011/uk_health_survey_2011_2.csv"
### Read the dataset straight from the web, name the dataframe "data"
df <- read.csv(url)
summary(df$compm13) # quick descriptive stats
summary(df$dnoft) # quick descriptive stats
summary(df$Age) # quick descriptive stats
summary(df$Sex) # quick descriptive stats
@jmrphy
jmrphy / uk_region_map.R
Created February 16, 2014 20:36
Map England's Government Office Regions
require(sp)
require(RColorBrewer)
require(memisc)
# get spatial data for Great Britain
con <- url("http://biogeo.ucdavis.edu/data/gadm2/R/GBR_adm2.RData")
print(load(con))
close(con)
gadm$NAME_1<-as.factor(gadm$NAME_1)
@jmrphy
jmrphy / eurobarometer_trend.r
Last active July 3, 2023 10:57
Eurobarometer 1970-2002 starter script
### Starter script for analyzing the Eurobarometer Trend data (1970-2002).
### Important: For this script to work, make sure to first set your working directory
### to a directory containing the Eurobarometer Trend dataset,
### named "eurobarometer_trends.dta." You can obtain this from their website or download
### the data file here: https://www.dropbox.com/s/5bdhel8l7c5r59z/eurobarometer_trends.dta?dl=0
### Outline:
### 1. Identify variables of interest and clean them up
### 2. Estimate a regression model of what makes people turnout for EP elections
@jmrphy
jmrphy / Rbasics.R
Last active December 11, 2015 20:29
# Some absolute basics of the R programming language.
# No data necessary, just load R and walk through this script.
####################################
### Warm up with some arithmetic ###
####################################
50 + 50 # addition
150 - 50 # subtraction
@jmrphy
jmrphy / gss_2010.R
Last active December 11, 2015 10:38
US General Social Survey 2010 starter script
############################################################
### 1. Download and install the packages you want to use ###
############################################################
### Packages are just collections of code written by other R users to simplify common
### tasks. For instance, R is very good at reading all kinds of data files.
### There is a package called "foreign" that lets you read in various data files
### with hardly any effort. We need it here because we have a .dta datafile.
### In the future, when you need to install a certain package, use this code but
### replace "foreign" in both lines with the name of your package.
@jmrphy
jmrphy / gazaunderattack.R
Created December 29, 2012 19:37
Analysis of #GazaUnderAttack tweets
x<-read.csv("tweets_#gazaunderattack.csv", header=FALSE, stringsAsFactors=FALSE)
x$username<-x$V2
x$text<-x$V5
#########################################
#### Nice Time-Series Plot ####
#########################################
library(ggplot2)
x$date <- strptime(x$V4, "%a, %d %b %Y %H:%M:%S %z", tz = "EST")
x$date <- as.POSIXct(x$date, tz = "EST")