Created
April 23, 2013 16:15
-
-
Save jkeefe/5445008 to your computer and use it in GitHub Desktop.
R Stats script used to process NYPD Stop & Frisk Data for map at http://project.wnyc.org/stop-frisk-delta/embed.html
This file contains hidden or 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
# load foreign package | |
library("foreign", lib.loc="/Library/Frameworks/R.framework/Versions/2.15/Resources/library") | |
# set working directory | |
setwd("/Volumes/JK-Spinner/Dropbox/Coding/r/stop-frisk-delta") | |
## To get the .por file into R, I turned on the "foreign" package | |
data2011<-read.spss("2011.por") | |
#check to see field names | |
names(data2011) | |
# change to data frame | |
# found here: http://www.statmethods.net/management/typeconversion.html | |
data2011<-as.data.frame(data2011) | |
# check to see dimension of data | |
dim(data2011) | |
# Selecting just the varibles we need | |
picvars <- c("SER_NUM", "XCOORD", "YCOORD") | |
csvdata <- data2011[picvars] | |
dim(csvdata) | |
names(csvdata) | |
# save as csv | |
# but don't quote out the values, so they're not considered strings | |
write.csv(csvdata,file="stop-frisk-2011-all-points.csv", quote = FALSE) | |
# -------------- | |
### do again for 2012 data | |
meddata2012<-read.spss("2012.por") | |
#check to see field names | |
names(data2012) | |
# change to data frame | |
# found here: http://www.statmethods.net/management/typeconversion.html | |
data2012<-as.data.frame(data2012) | |
# check to see dimension of data | |
dim(data2012) | |
# Selecting just the varibles we need | |
picvars <- c("SER_NUM", "XCOORD", "YCOORD") | |
csvdata <- data2012[picvars] | |
dim(csvdata) | |
names(csvdata) | |
# save as csv | |
# but don't quote out the values, so they're not considered strings | |
write.csv(csvdata,file="stop-frisk-2012-all-points.csv", quote = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment