-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_crimes.R
More file actions
18 lines (15 loc) · 976 Bytes
/
data_crimes.R
File metadata and controls
18 lines (15 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Munging the crimes data
crimedata <- st_read(paste0("https://data.montgomerycountymd.gov/resource/icn6-v9z3.geojson?",
"$where=date_extract_y(start_date)=2018",
"&$limit=184568"))
crimedata %<>% st_transform(crs=4269) %>%
st_join(mocodata %>% select(GEOID),left=TRUE) %>% # Intersect with the geoids
filter(crimename1 != "Not a Crime") %>% # We only want actual crimes
mutate(crimename1 = case_when(crimename1 == "Crime Against Person" ~ "personcrime",
crimename1 == "Crime Against Property" ~ "propertycrime",
crimename1 == "Crime Against Society" ~ "societycrime",
crimename1 == "Other" ~ "othercrime")) %>%
group_by(GEOID,crimename1) %>% # Group on tract and crime type
count() %>%
st_drop_geometry() %>% # Dropping geometry for simplicity
pivot_wider(id_cols = GEOID,names_from=crimename1,values_from=n)