Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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),
# 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
You can’t perform that action at this time.