library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 4.0.0 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
filepath1_read <- "D:/DATA 205"
filepath2_write <- "D:/DATA 205/Written from R"
setwd(filepath1_read)
dispatch <- read_csv("Police_Dispatched_Incidents_20260216.csv")
## Rows: 17314 Columns: 26
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): Incident_ID, Start Time, End Time, Initial Type, Close Type, Addre...
## dbl (14): Crime Reports, Crash Reports, Priority, Zip, Longitude, Latitude, ...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
uof <- read_csv("POL-_Use_of_Force_Details_20260216.csv")
## Rows: 392 Columns: 118
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (19): ReportGUID, OfficerGUID, Event Date/Time, CR # or Event #, Event C...
## dbl (5): Subj Age, Subj Height, Subj Weight, Ofc Age, Ofc CEW # of Cartridges
## lgl (94): Reason - Counteract, Reason - Claim Injury, Reason - Protective In...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
crime <- read_csv("Crime_20260216.csv")
## Rows: 3965 Columns: 30
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (22): Dispatch Date / Time, Start_Date_Time, End_Date_Time, NIBRS Code, ...
## dbl (8): Incident ID, Offence Code, CR Number, Victims, Zip Code, Address N...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
uof <- uof |>
rename("Crime Reports" = "CR # or Event #")
uof <- uof |>
filter(!(str_starts(uof$`Crime Reports`, "P")))
uof <- uof |>
filter(!(str_starts(uof$`Crime Reports`, "p")))
unique(uof$`Crime Reports`[is.na(as.numeric(uof$`Crime Reports`))])
## character(0)
uof2 <- uof |>
mutate("Crime Reports" = parse_double(uof$`Crime Reports`))
data <- inner_join(dispatch, uof2, by="Crime Reports")
setwd(filepath2_write)
write.csv(data, "July 2025 Dispatch and Use of Force.csv")
#unique(crime$`CR Number`[is.na(as.numeric(crime$`CR Number`))])
crime <- crime |>
rename("Crime Reports" = "CR Number")
data2 <- inner_join(crime, data, by="Crime Reports")
## Warning in inner_join(crime, data, by = "Crime Reports"): Detected an unexpected many-to-many relationship between `x` and `y`.
## ℹ Row 126 of `x` matches multiple rows in `y`.
## ℹ Row 1 of `y` matches multiple rows in `x`.
## ℹ If a many-to-many relationship is expected, set `relationship =
## "many-to-many"` to silence this warning.
setwd(filepath2_write)
write.csv(data2, "July 2025 Dispath and UoF and Crime.csv")