Skip to content

Instantly share code, notes, and snippets.

## Code to Download Nike Images
setwd("~/Documents/Project/What\ Are\ Those?/classes/nike")
nike = data %>% filter(brand=="nike")
nike_images = nike %>% select(image, photo_index, photo_name)
for(i in seq(1:nrow(nike_images))){
print(paste0(paste0(i,"/"),as.character(nrow(nike_images))))
download.file(nike_images$image[i], nike_images$photo_name[i])
}
############### By Time
# We want to organize the crashes by hours
date_hour = strptime(vehc$TIME,"%H")
hour = as.numeric(format(date_hour, "%H")) +
as.numeric(format(date_hour, "%M"))/60
vehc$hour = hour
common_times = vehc %>% group_by(hour) %>%
summarize(count=n()) %>%
arrange(desc(count))
# Summarizing the data by year
crashes_in_2015 = zip_counts %>% filter(year==2015)
crashes_in_2014 = zip_counts %>% filter(year==2014)
crashes_in_2013 = zip_counts %>% filter(year==2013)
## Get the diffs for 2014 vs 2015
y2015.vs.y2014 = left_join(crashes_in_2015,crashes_in_2014,by = 'region')
df20152014 = as.data.frame(y2015.vs.y2014) %>% select(year.x,region,value.x,value.y)
df20152014 = df20152014 %>% mutate(value=value.x-value.y)
# 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 %>%