Skip to content

Instantly share code, notes, and snippets.

@felixhaass
Created October 19, 2013 11:04
Show Gist options
  • Save felixhaass/7054500 to your computer and use it in GitHub Desktop.
Save felixhaass/7054500 to your computer and use it in GitHub Desktop.
This code ranks all African states that have contributed troops to UN Peacekeeping Operations by summing their monthly contributions. Note that this does not equal each country's actual troop deployment over time, since the scripts simply sums each monthly contribution which might not actually differ from the country's contribution in the preced…
pko <- read.table("./data/Data.Full.csv", header=TRUE, sep=",")
pkoAfricaTotal <- pko[pko$tcc.continent=="Africa", ] # subset all African TCCs
contribSum <- rowsum(pkoAfricaTotal$total,
pkoAfricaTotal$tcc) # sum all contributions
topTCC <- contribSum[order(contribSum[,1], decreasing=TRUE), ] # order countries
# convert to dataframe
topTCC <- data.frame(Country=names(topTCC),
Troops=unlist(topTCC),
row.names=NULL)
# pretty format for large numbers
topTCC$Troops <- format(topTCC$Troops, big.mark=" ")
topTCC$Rank <- 1:length(topTCC$Country) # add rank
topTCC <- topTCC[c("Rank", "Country", "Troops")] # assign column names
# write 'topTCC' using write.table() etc. or copy & paste
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment