Skip to content

Instantly share code, notes, and snippets.

@evanemolo
Created September 9, 2012 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanemolo/6803de1013577ae9fd2d to your computer and use it in GitHub Desktop.
Save evanemolo/6803de1013577ae9fd2d to your computer and use it in GitHub Desktop.
DWB Assignment 1
# DWB - Assignment 1
# Part One
data <- read.csv("http://www.jakeporway.com/teaching/data/snf_11_2011_1.csv", header=TRUE, as.is=TRUE)
# How many women were stopped?
sum(data$sex == "F")
[1] 3927
# What percentage of the stops is this?
sum(data$sex == "F") / length(data$sex)
[1] 0.06760316
# How many different kinds of suspected crimes are there?
length(table(data$crime.suspected))
[1] 1356
# What do you think about that?
# I have no opinion on how many different kinds of suspected crimes there are.
# Which precinct had the most stops? How many were there?
max(table(data$precinct))
[1] 2597
which(table(data$precinct) == 2597)
47
# Which precinct had the least stops?
min(table(data$precinct))
[1] 139
which(table(data$precinct) == 139)
13
# How many people between 18 and 30 were stopped?
sum(data$age >= 18 & data$age <= 30)
[1] 29865
# Find the number of people who were given the full treatment: frisked, searched,
# and then arrested
length(which(data$frisked == 1 & data$searched == 1 & data$arrested == 1))
[1] 1829
# Make a histogram of their ages.
frisk.search.arrest = which(data$frisked == 1 & data$searched == 1 & data$arrested == 1)
subset.of.people = data[frisk.search.arrest, ]
subset.of.people.age = subset.of.people$age
hist(subset.of.people.age)
########################################################
# Part Two
# Part Two dataset is available at: https://www.google.com/fusiontables/DataSource?docid=1IjJSw2MpTXL64gqUWKN45-FgnbISMs_sVcC1Kw
bike.rack.data = read.csv("/Users/evanemolo/Dropbox/_ITP/_Fall_2012/DWB/HW/NYC-Bike-Rack-locations.csv", header=TRUE, as.is=TRUE)
bike.racks.lat.long = bike.rack.data[,c("Latitude","Longitude")]
plot(bike.racks.lat.long)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment