Plainview City

Setup

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.3     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ 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
library(janitor)

Attaching package: 'janitor'

The following objects are masked from 'package:stats':

    chisq.test, fisher.test
library(readxl)
library(lubridate)

Import

Same process as before

plainview <- read_excel("data-raw/PlainviewCity.xlsx")

plainview |> glimpse()
Rows: 468
Columns: 14
$ `UCR/NCIC`       <chr> NA, "35A,3562", NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
$ `Event Number`   <chr> NA, "1800524", "1800553", "1801115", "1801116", "1801…
$ name             <chr> NA, "Indrebo, Chase Kendall", "Tonche Enriquez, Emman…
$ charges          <chr> NA, "CONTROLLED SUBSTANCE - Marijuana, Possession", "…
$ geox             <chr> NA, "34.198", "34.197000000000003", "34.1910000000000…
$ geoy             <dbl> NA, -101.749, -101.720, -101.723, -101.694, -101.748,…
$ address_arrest   <chr> NA, "1601 N I 27", "1700 W 15TH", "1700 W 11TH", "700…
$ date_arrest      <dttm> NA, 2018-01-07, 2018-01-08, 2018-01-14, 2018-01-14, …
$ time_arrest      <dttm> NA, 1899-12-31 18:42:00, 1899-12-31 01:14:00, 1899-1…
$ `Dispatch Dispo` <chr> NA, "ARR", "ARR", "ARR", "ARR", "ARR", "ARR", "ARR", …
$ case_status      <chr> NA, "CLEARED ADULT ARREST", "CLEARED ADULT ARREST", "…
$ age              <dbl> NA, 23, 24, 30, 27, 31, 18, 23, NA, 33, 17, 18, 17, 3…
$ race             <chr> NA, "w", "h", "b", "h", "w", "h", "h", NA, "h", "h", …
$ sex              <chr> NA, "m", "m", "m", "f", "f", "m", "f", NA, "f", "m", …

Clean

Need to get rid of extra columns and change date_arrest and time_arrest to datetime_arrest and datetime object.

plainview_clean <- plainview |> mutate(
  datetime_arrest = paste(date_arrest,substr(time_arrest,12,19) )
  ) |> select(
    -"UCR/NCIC", 
    -"Event Number", 
    -time_arrest,
    -"Dispatch Dispo",
    -case_status,
    -geox,
    -geoy,
) |> mutate( datetime_arrest = ymd_hms(datetime_arrest)) |> 
  cbind(agency_arrest = NA, ethnicity = NA)
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `datetime_arrest = ymd_hms(datetime_arrest)`.
Caused by warning:
!  1 failed to parse.
plainview_clean |> glimpse()
Rows: 468
Columns: 10
$ name            <chr> NA, "Indrebo, Chase Kendall", "Tonche Enriquez, Emmanu…
$ charges         <chr> NA, "CONTROLLED SUBSTANCE - Marijuana, Possession", "C…
$ address_arrest  <chr> NA, "1601 N I 27", "1700 W 15TH", "1700 W 11TH", "700 …
$ date_arrest     <dttm> NA, 2018-01-07, 2018-01-08, 2018-01-14, 2018-01-14, 2…
$ age             <dbl> NA, 23, 24, 30, 27, 31, 18, 23, NA, 33, 17, 18, 17, 31…
$ race            <chr> NA, "w", "h", "b", "h", "w", "h", "h", NA, "h", "h", "…
$ sex             <chr> NA, "m", "m", "m", "f", "f", "m", "f", NA, "f", "m", "…
$ datetime_arrest <dttm> NA, 2018-01-07 18:42:00, 2018-01-08 01:14:00, 2018-01…
$ agency_arrest   <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
$ ethnicity       <lgl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…

Export

plainview_clean |> write_csv("data-processed/Plainview-City.csv")