Skip to content

Instantly share code, notes, and snippets.

@ulfelder
Created May 30, 2013 21:22
Show Gist options
  • Save ulfelder/5681347 to your computer and use it in GitHub Desktop.
Save ulfelder/5681347 to your computer and use it in GitHub Desktop.
R script for a human-assisted process to screen GDELT for atrocities
# Clear the workspace
rm(list=ls(all=TRUE))
# Set working directory to location of extracted daily update and .txt file with column headers
# setwd("PUT YOUR DIRECTORY NAME HERE")
# Load function to return subset involving violence against civilians
extractor <- function(date) {
filename <- paste(date,"export.csv", sep=".")
dailies <- read.delim(filename, header=FALSE)
header <- read.delim("csv.header.dailyupdates.txt", header=TRUE)
names(dailies) <- names(header)
z <- subset(dailies,
( EventCode==180 | EventCode==1823 |
EventCode==190 | EventCode==193 | EventCode==194 | EventCode==195 |
EventCode==200 | EventCode==201 | EventCode==202 | EventCode==203 |
EventCode==204 | EventCode==205 ) &
((Actor2Type1Code=="CVL" | Actor2Type1Code=="OPP" |
Actor2Type1Code=="EDU" | Actor2Type1Code=="LAB" |
Actor2Type1Code=="REL" | Actor2Type1Code=="HLH" |
Actor2Type1Code=="REF" | Actor2Type1Code=="MED" ) |
(Actor2Type2Code=="CVL" | Actor2Type2Code=="OPP" |
Actor2Type2Code=="EDU" | Actor2Type2Code=="LAB" |
Actor2Type2Code=="REL" | Actor2Type2Code=="HLH" |
Actor2Type2Code=="REF" | Actor2Type2Code=="MED" )) &
((Actor1Type1Code=="GOV" | Actor1Type1Code=="MIL" |
Actor1Type1Code=="COP" | Actor1Type1Code=="SPY" |
Actor1Type1Code=="REB" | Actor1Type1Code=="SEP" ) |
(Actor1Type2Code=="GOV" | Actor1Type2Code=="MIL" |
Actor1Type2Code=="COP" | Actor1Type2Code=="SPY" |
Actor1Type2Code=="REB" | Actor1Type2Code=="SEP" )) )
z1 <- subset(z, select=c(GLOBALEVENTID, Actor1Name, Actor2Name, EventCode,
ActionGeo_FullName, SOURCEURL))
z1$ushmm.screened <- 1 # Marker for events we reviewed
z1$ushmm.eoi <- 0 # Marker for events that look like atrocities
return(z1)
}
# Extract the subset of interest
today <- "yyyymmdd" ### INSERT DATE OF RELEVANT DAILY UPDATE ###
set <- extractor(today)
# Open subset in table and manually code event marker (ushmm.eoi)
# based on criteria specified in accompanying manual
fix(set)
# Write out the results as a .csv
write.csv(set, sprintf("%s.atrocities.csv", today), row.names=F)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment