Political piece is here.
# Prototyping analysis of summary of BPD Offenses 11:09 PM 8/8/2015
# Three months of summary offenses with Time, Location,Offense,Code
# http://www.cob.org/services/safety/police/daily-activity.aspx
library(dplyr)
library(lattice)
# scrape the summary screen, paste the data into Scalc (Open Office) or another spreadsheet, massage into a four column CSV
COB_05.10_08.07.2015 <- read.csv("COB_3Months.csv",sep=",",stringsAsFactors=FALSE)
COB <- COB_05.10_08.07.2015
Offense <- as.data.frame(count(COB,Offense,sort=TRUE))[1:20,]
Location <- as.data.frame(count(COB,Location,sort=TRUE))[1:20,]
print("Top 20 for Offense and Location")
Offense
Location
print("From a subset top 20 offenses: Locations from Offenses greater than 5 incidents")
ndim <- c("Location","n","Offense")
List <- matrix(data = NA, nrow = 1, ncol = 3, byrow = TRUE)
colnames(List) <- ndim
List <- data.frame(List)
# rbind the top 20 offenses with their locations and sort by descending those locations > 5
for( i in as.list(Offense$Offense))
{
List <- rbind(List,subset(data.frame(count(subset(COB, Offense == i),Location,sort=TRUE),"Offense"=i),n > 5))
}
# remove NA line from above
List <- arrange(List[-1,],desc(n))
List
# Make some barcharts
barchart(Location ~n ,data=List,horizontal=TRUE)
mtext("From a subset of top 20 BPD Offenses: Locations with Offenses greater than 5 incidents between 05.10 - 08.07 2015.",line=2)
barchart(Offense ~n ,data=List,horizontal=TRUE)
mtext("From a subset of top 20 BPD Offenses: Offenses with Locations greater than 5 incidents between 05.10 - 08.07 2015.",line=2)
No comments:
Post a Comment