This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################ | |
### 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |