Created
February 6, 2024 15:05
-
-
Save CharlesFainLehman/ea82b526c7db13b2fb46a8a761cd6498 to your computer and use it in GitHub Desktop.
This code counts top-level charges in a New York DOC daily inmates file.
This file contains hidden or 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
library(tidyverse) | |
#you'll need this file, available in my repo, at | |
#https://github.com/CharlesFainLehman/Rikers-DIC/blob/main/dat/via_github/DOC_Inmates_InCustody_Daily_20231127.csv | |
#You can also use any other DIC file, though, updated daily at | |
#https://data.cityofnewyork.us/Public-Safety/Daily-Inmates-In-Custody/7479-ugqb | |
#or stored in my github repo at | |
#https://github.com/CharlesFainLehman/Rikers-DIC/ | |
rikers_11_26_23 <- read.csv("Daily_Inmates_In_Custody_20231127.csv") | |
count(rikers_11_26_23) | |
rikers_11_26_23 %>% | |
separate(TOP_CHARGE, into = c("Title", "Section"), sep = "\\.") %>% | |
mutate(Attempt = grepl("110-", Title), | |
Title = gsub("110-", "", Title)) %>% | |
count(Title) %>% | |
arrange(-n) -> top_charges | |
#The top charge codes are: | |
#125: Homicide | |
#160: Robbery | |
#120: Assault | |
#140: Burglary | |
#265: Guns | |
print(top_charges) | |
#This is the fraction of 3,300 | |
slice_max(top_charges, order_by = n, n = 5) %>% | |
summarise(n = sum(n)) %>% | |
pull(n)/3300 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment