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
rm(list=ls()) | |
toInstall <- c("ggplot2", "maptools", "animation", "rgdal") | |
lapply(toInstall, library, character.only=TRUE) | |
# Load and clean World Governance Indicators (WGI) data | |
# Can be downloaded here https://dl.dropboxusercontent.com/u/18955935/wgi_final.RData | |
# Most of the cleaning involving matching World Bank naming system with that of the map | |
load('./data/wgi_cleaned.RData') | |
# Load world map shape file (Google "TM_WORLD_BORDERS_SIMPL-0.3") |
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(xtable) | |
corstarsl <- function(x){ | |
require(Hmisc) | |
x <- as.matrix(x) | |
R <- rcorr(x)$r | |
p <- rcorr(x)$P | |
## define notions for significance levels; spacing is important. | |
mystars <- ifelse(p < .001, "***", ifelse(p < .01, "** ", ifelse(p < .05, "* ", " "))) |
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
# Truly the most ridiculous thing I could think of. | |
doInstall <- TRUE # Change to FALSE if you don't want packages installed. | |
toInstall <- c("XML", "png", "devtools", "RCurl") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
# Some helper functions, lineFinder and makeTable | |
source_gist("818983") | |
source_gist("818986") |
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
doInstall <- TRUE | |
toInstall <- c("twitteR", "dismo", "maps", "ggplot2") | |
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")} | |
lapply(toInstall, library, character.only = TRUE) | |
<<<<<<< HEAD | |
# make some change | |
======= | |
>>>>>>> 0f79b1430f148bded0527f9c67906de7c0667fce |
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
#!/bin/sh | |
MYSQL_ARGS="--defaults-file=/etc/mysql/debian.cnf" | |
DB="mbctest" | |
DELIM=";" | |
CSV="$1" | |
TABLE="$2" | |
[ "$CSV" = "" -o "$TABLE" = "" ] && echo "Syntax: $0 csvfile tablename" && exit 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
# verb.coop | |
SELECT YEAR(e.event_date) AS year | |
, MONTH(e.event_date) AS month | |
, cSource.ISOA3Code AS source_country | |
, cTarget.ISOA3Code AS target_country | |
, COUNT(*) AS verb_coop | |
FROM simple_events e | |
JOIN eventtypes t ON e.eventtype_id = t.eventtype_ID | |
JOIN countries cSource ON e.source_country_id = cSource.id | |
JOIN countries cTarget ON e.target_country_id = cTarget.id |
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
## A Guide on Install RMySQL on Windows | |
I have encountered various error messages during installation, including | |
* mysql.h not found | |
* cygwin path warning | |
Just install a fresh install of MySQL Server (no need for Workbench and Connector, or anything else). | |
Here are the steps: | |
1. Download MySQL installer (which contains all products) from [here](http://dev.mysql.com/downloads/windows/installer/) |
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
# Install and load packages | |
f_install_and_load <- function(packs) { | |
new.packs <- packs[!(packs %in% installed.packages()[ ,"Package"])] | |
lapply(new.packs, install.packages, repos="http://cran.rstudio.com/", dependencies=TRUE) | |
lapply(packs, library, character.only=TRUE) | |
} | |
# Scale and center a numeric vector | |
f_center_and_scale <- function(vector, num.sd = 2) { | |
# num.sd is how many sd to divide by |
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
# Multiple plot function | |
# | |
# ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects) | |
# - cols: Number of columns in layout | |
# - layout: A matrix specifying the layout. If present, 'cols' is ignored. | |
# | |
# If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), | |
# then plot 1 will go in the upper left, 2 will go in the upper right, and | |
# 3 will go all the way across the bottom. | |
# |
OlderNewer