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
library(XML) | |
library(plyr) | |
# Get and format html file | |
duke.html <- readLines("http://www.gradeinflation.com/Duke.html") | |
duke.doc <- htmlParse(duke.html) | |
# Get table as data frame | |
duke <- readHTMLTable(duke.doc, header=F, as.data.frame=F) | |
duke <- data.frame(duke, stringsAsFactors=F) |
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
plotMissing <- function(data, dim1=NULL, dim2=NULL, na.id=NULL) { | |
require(ggplot2) | |
require(grid) | |
# Function to plot missing values in a data frame, or to plot missing values | |
# in a data frame representing panel data (i.e. against 2 dimensions) | |
# Leave dim1 and dim2 NULL to plot missing values in data frame. | |
if (xor(is.null(dim1), is.null(dim2))) stop("Specify either both or no dims.") | |
# Set colors for possible data values | |
myCol <- c("#DCDCDC", "#32CD32", "#CD4F39") |
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
CREATE TABLE afg_greg AS | |
SELECT * | |
FROM greg | |
WHERE ( ST_contains((SELECT the_geom FROM afg_adm0), geom) OR | |
ST_overlaps((SELECT the_geom FROM afg_adm0), geom) ); |
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
library(geonames) | |
# list of city names (in Afghanistan) | |
cities <- c("Gereshk", "Lashkar Gah", "Marjah", "Nad-e Ali") | |
-5L), class = "data.frame") | |
# conveninence function to look up and format results | |
GNsearchAF <- function(x) { | |
res <- GNsearch(name=x, country="AF") | |
return(res[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
# | |
# | |
# Original code from Mike: | |
# | |
# | |
# mdw attempts at modeling Protests & Demonstrations | |
# August 13, 2013 | |
library(wicews) |
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
egy.points <- | |
structure(list(Latitude = c(30.0626, 30.0626, 30.0626, 25, 30.5, | |
30.1219, 29.0744, 31.4044, 29.9737, 30.0626, 31.4, 31.2, 29, | |
30.6, 28.1, 26.1642, 24.0934, 25.6989, 27, 30.0453, 30.6043, | |
30.6803, 30.4658, 31.2565, 30.1219, 27.7667, 31.0364, 30.0273, | |
31.4044, 29.7, 27.2, 26.5, 29.5, 26, 28.501, 27.9333, 30.5, 27.2574, | |
27, 30.2986, 30.5333, 29.7, 27.2167, 30.7885, 25.0757, 30.9, | |
30.7, 30.9, 24.0934, 29.9978, 31.1, 30.15, 22.3457, 25.9141, | |
30.6, 31.35, 26.1642, 28.3121, 26.55, 30.9251, 31.0392, 30.5, | |
27, 29.3, 26.0495, 31, 26.0549, 26.1247, 30.3, 26.7292, 30.0626, |
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
library(ggmap) | |
library(source.gist) | |
# Get data frame with coordinates for points | |
source.gist("6705264") | |
head(egy.points) | |
# Get background map | |
egy.map <- get_map(location=c(lon=30, lat=26), zoom=6, maptype="terrain", filename="~/Desktop/ggmapTemp") | |
p <- ggmap(egy.map) + |
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
turkey.prot <- | |
structure(list(source = c("icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", | |
"icews", "icews", "icews", "icews", "icews", "icews", "icews", |
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
library(ggmap) | |
library(source.gist) | |
# Get data frame with coordinates for points | |
source.gist("6765348") | |
head(turkey.prot) | |
# Get background map | |
tr.map <- get_map(location=c(lon=34, lat=37), zoom=5, maptype="terrain", filename="~/Desktop/ggmapTemp") | |
p <- ggmap(tr.map) + |
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
# Libraries | |
library(RMySQL) | |
# Connect to server | |
conn <- dbConnect(MySQL(), user="ab428", password="", | |
dbname="event_data", host="") | |
country <- "Turkey" | |
start.date <- "2013-05-15" | |
end.date <- "2013-06-15" |
OlderNewer