Created
February 26, 2021 20:25
-
-
Save tradingbills/882da713d44a84b333946fac035dc736 to your computer and use it in GitHub Desktop.
This file contains 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
```{r} | |
#set UCR codes for Chicago | |
# 2020 http://gis.chicagopolice.org/website/clearMap_crime_sums/crime_types.html | |
# 2021 http://directives.chicagopolice.org/forms/CPD-63.451_Table.pdf | |
# 2021 above from footer of http://directives.chicagopolice.org/directives/data/a7a57bf0-12d7196c-11f12-d71a-3c76ad6f2c11950a.html | |
# 2021 above search from | |
# 388v01::34:51 which | |
# 538, grepl | |
# Murder | |
UCR01 = "0110|0130" | |
# Sexual Assault | |
UCR02 = "0261|0262|0263|0264|0265|0266|0271|0272|0273|0274|0275|0281|0291|1753|1754" | |
# Robbery | |
UCR03 = "0312|0313|031A|031B|0320|0325|0326|0330|0331|0334|0337|033A|033B|0340" | |
# Aggravated Assault | |
UCR04A = "051A|051B|0520|0530|0550|0551|0552|0553|0555|0556|0557|0558" | |
# Aggravated Battery | |
UCR04B = "041A|041B|0420|0430|0450|0451|0452|0453|0461|0462|0479|0480|0481|0482|0483|0485|0488|0489|0490|0491|0492|0493|0495|0496|0497|0498" | |
``` | |
```{r} | |
# assert == VC by UCR code & append logical vector | |
#or str_detect with regex #539 | |
chig_gte2015$GUCR = ifelse(grepl(UCR01, chig_gte2015$IUCR), "UCR01", | |
ifelse(grepl(UCR02, chig_gte2015$IUCR), "UCR02", | |
ifelse(grepl(UCR03, chig_gte2015$IUCR), "UCR03", | |
ifelse(grepl(UCR04A, chig_gte2015$IUCR), "UCR04A", | |
ifelse(grepl(UCR04B, chig_gte2015$IUCR), "UCR04B", "NVC"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment