Last active
June 27, 2020 19:38
-
-
Save tradingbills/fff357a2f52b535aa90586a2f34323f6 to your computer and use it in GitHub Desktop.
Violent Crime Codes Chicago
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
# IUCR codes for Ill. define for ifelse grepl below | |
# code found at # http://gis.chicagopolice.org/website/clearMap_crime_sums/crime_types.html | |
UCR01 = "0110|0130" | |
UCR02 = "0261|0262|0263|0264|0265|0266|0271|0272|0273|0274|0275|0281|0291|1753|1754" | |
UCR03 = "0312|0313|031A|031B|0320|0325|0326|0330|0331|0334|0337|033A|033B|0340" | |
UCR04A = "051A|051B|0520|0530|0550|0551|0552|0553|0555|0556|0557|0558" | |
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" | |
# assert == VC by UCR code & append col GUCR for a global variable holding codes in long form for respective crimes | |
chicago_ds_2015_gte$GUCR = ifelse(grepl(UCR01, chicago_ds_2015_gte$IUCR), "UCR01", | |
ifelse(grepl(UCR02, chicago_ds_2015_gte$IUCR), "UCR02", | |
ifelse(grepl(UCR03, chicago_ds_2015_gte$IUCR), "UCR03", | |
ifelse(grepl(UCR04A, chicago_ds_2015_gte$IUCR), "UCR04", | |
ifelse(grepl(UCR04B, chicago_ds_2015_gte$IUCR), "UCR04", "NVC"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
replaced orginal use of grepl , str_detect with regex #539