This is my script for crime data
if(!require(tidyverse))install.packages("tidyverse")
## Loading required package: 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 3.4.4 ✔ 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
library(tidyverse)
mydata <- read.csv("https://drkblake.com/wp-content/uploads/2024/02/CrimeData.csv")
SigByCounty <- mydata
SigByCounty <- group_by(SigByCounty, Description, Agency)
SigByCounty <- summarize(SigByCounty, Count = n())
## `summarise()` has grouped output by 'Description'. You can override using the
## `.groups` argument.
SigByCounty <- pivot_wider(SigByCounty,
names_from = Agency,
values_from = Count)
head(SigByCounty, 20)
## # A tibble: 14 × 3
## # Groups: Description [14]
## Description `Murfreesboro Police` `Clarksville Police`
## <chr> <int> <int>
## 1 Arson 1 NA
## 2 Assault 199 29
## 3 Child Abuse 6 NA
## 4 DUI 33 8
## 5 Disorderly Conduct 24 13
## 6 Drugs 126 30
## 7 Fraud 66 11
## 8 Rape 2 NA
## 9 Robbery/Burglary 29 12
## 10 Sex crime 11 NA
## 11 Stalking 6 NA
## 12 Theft 206 25
## 13 Vandalism 44 8
## 14 Weapon violation 13 8