Created
September 20, 2012 15:37
-
-
Save evanemolo/3756654 to your computer and use it in GitHub Desktop.
DWB-race-top-crimes
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
snf <- read.csv("http://www.jakeporway.com/teaching/data/snf_2.csv", as.is=TRUE) | |
crime.abbr = substr(snf$crime.suspected, 1, 3) | |
snf$crime.abbr = crime.abbr | |
race.code = c(-1,1,2,3,4,5,6) | |
for(i in race.code) { | |
# create subset | |
which.race = which(snf$race == i) | |
subset.race = snf[which.race, ] | |
# target crime.abbr col in subset | |
subset.race.crime.abbr = subset.race$crime.abbr | |
# keep it organized... | |
print(paste("racecode", i, "results:")) | |
# reverse sort table, target top 3 crimes, then print | |
print(rev(sort(table(subset.race.crime.abbr)))[1:3]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment