I am working with the GTD database- can be downloaded at (http://www.start.umd.edu/gtd/contact/)
I have a subset of the data only for the United States, and what I am trying to do is add information on if the political party in power is Republican or Democrat. The years I am using come from http://candychang.com/?p=4346
My very basic knowledge of R has lead me to this,
gtd<- read.csv("gtd.csv")
US <- subset(x=gtd, country_txt== "United States")
Republican <- subset(x=US, iyear %in% c(1971:1976, 1981:1992, 2001:2008))
Democrat <- subset(x=US, iyear %in% c(1977:1980, 1993:2000, 2009:2011))
install.packages("plyr")
require(plyr)
republicanattacks <- ddply(Republican, .(iyear), "nrow")
democratattacks<- ddply(Democrat, .(iyear), "nrow")
transform(republicanattacks, new="Republican")
transform(democratattacks, new="Democrat")
rbind(republicanattacks,democratattacks) #does not work- Error in match.names(clabs, names(xi)) :
names do not match previous names
I want to basically just stick these data frames together so I can make one graph but I haven't been able to do that. Ultimately my goal is to display the number of attacks for republican/democrats graphically to show the comparison, and I don't want to do this on separate graphs- I am sure there is an easy way to merge these but the ways I've tried haven't work. I was also wondering if there is a more simple way to do this starting with the US subset like with a For loop or something, I am just very unfamiliar with for loops. But basically I just need to know how to merge these..