Skip to content

Instantly share code, notes, and snippets.

@yeere91
Last active October 24, 2016 04:24
Show Gist options
  • Save yeere91/7ff71dea32260f0b4cfd34a708c4d8b7 to your computer and use it in GitHub Desktop.
Save yeere91/7ff71dea32260f0b4cfd34a708c4d8b7 to your computer and use it in GitHub Desktop.
# Import the dataset
vehc = read.csv("NYPD_Motor_Vehicle_Collisions.csv")
# Create a year column
v = strsplit(as.character(vehc$DATE),"/")
v1 = matrix(unlist(v), ncol=3, byrow=TRUE)
vehc$year = v1[,3]
# Aggregrate by ZIP.CODE
zip_counts = vehc %>%
group_by(year,ZIP.CODE) %>%
summarize(count = n()) %>%
select(year, ZIP.CODE, value = count) %>%
mutate(region = as.character(ZIP.CODE))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment