fatal police shooting

Author

Kenneth Nguyen

Published

March 12, 2026

Is there any connection of the race of the person with them being armed? I am using this data set called “Fatal Police Shootings” from the website openintro. It contains records of every fatal police shooting by an on-duty officer since January 1, 2015. And it is a data frame with 6421 rows and 12 variables.We are focusing on only two variables being race and armed as they are the only variables that are needed to answer the question.

Load the libraries

library(tidyverse)
Warning: package 'tidyverse' was built under R version 4.5.2
Warning: package 'ggplot2' was built under R version 4.5.2
Warning: package 'tibble' was built under R version 4.5.2
── 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.2     ✔ tibble    3.3.1
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.1.0     
── 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(dplyr)
library(ggplot2)
setwd("~/Data 101")
shootings <- read.csv("fatal_police_shootings.csv")

#Look at the armed variable

unique(shootings$armed)
 [1] "gun"                              "unarmed"                         
 [3] "toy weapon"                       "nail gun"                        
 [5] "knife"                            ""                                
 [7] "shovel"                           "vehicle"                         
 [9] "hammer"                           "hatchet"                         
[11] "sword"                            "machete"                         
[13] "box cutter"                       "undetermined"                    
[15] "metal object"                     "screwdriver"                     
[17] "lawn mower blade"                 "flagpole"                        
[19] "guns and explosives"              "cordless drill"                  
[21] "crossbow"                         "BB gun"                          
[23] "metal pole"                       "Taser"                           
[25] "metal pipe"                       "metal hand tool"                 
[27] "blunt object"                     "metal stick"                     
[29] "sharp object"                     "meat cleaver"                    
[31] "carjack"                          "chain"                           
[33] "contractor's level"               "railroad spikes"                 
[35] "stapler"                          "beer bottle"                     
[37] "unknown weapon"                   "binoculars"                      
[39] "bean-bag gun"                     "baseball bat and fireplace poker"
[41] "straight edge razor"              "gun and knife"                   
[43] "ax"                               "brick"                           
[45] "baseball bat"                     "hand torch"                      
[47] "chain saw"                        "garden tool"                     
[49] "scissors"                         "pole"                            
[51] "pick-axe"                         "flashlight"                      
[53] "baton"                            "spear"                           
[55] "chair"                            "pitchfork"                       
[57] "hatchet and gun"                  "rock"                            
[59] "piece of wood"                    "pipe"                            
[61] "glass shard"                      "motorcycle"                      
[63] "pepper spray"                     "metal rake"                      
[65] "crowbar"                          "oar"                             
[67] "machete and gun"                  "tire iron"                       
[69] "air conditioner"                  "pole and knife"                  
[71] "baseball bat and bottle"          "fireworks"                       
[73] "pen"                              "chainsaw"                        
[75] "gun and sword"                    "gun and car"                     
[77] "pellet gun"                       "claimed to be armed"             
[79] "incendiary device"                "samurai sword"                   
[81] "bow and arrow"                    "gun and vehicle"                 
[83] "vehicle and gun"                  "wrench"                          
[85] "walking stick"                    "barstool"                        
[87] "grenade"                          "BB gun and vehicle"              
[89] "wasp spray"                       "air pistol"                      
[91] "Airsoft pistol"                   "baseball bat and knife"          
[93] "vehicle and machete"              "ice pick"                        
[95] "car, knife and mace"              "bottle"                          
[97] "gun and machete"                  "microphone"                      
[99] "knife and vehicle"               

Using the unique code, it allows me to see everything that is in the armed variable. And I can see the “” which is a blank on the dataset. So I will need to remove it

The progress of removing “”

shootingsfix1 <- gsub(" ","NA",shootings$armed)
unique(shootingsfix1)
 [1] "gun"                                 
 [2] "unarmed"                             
 [3] "toyNAweapon"                         
 [4] "nailNAgun"                           
 [5] "knife"                               
 [6] ""                                    
 [7] "shovel"                              
 [8] "vehicle"                             
 [9] "hammer"                              
[10] "hatchet"                             
[11] "sword"                               
[12] "machete"                             
[13] "boxNAcutter"                         
[14] "undetermined"                        
[15] "metalNAobject"                       
[16] "screwdriver"                         
[17] "lawnNAmowerNAblade"                  
[18] "flagpole"                            
[19] "gunsNAandNAexplosives"               
[20] "cordlessNAdrill"                     
[21] "crossbow"                            
[22] "BBNAgun"                             
[23] "metalNApole"                         
[24] "Taser"                               
[25] "metalNApipe"                         
[26] "metalNAhandNAtool"                   
[27] "bluntNAobject"                       
[28] "metalNAstick"                        
[29] "sharpNAobject"                       
[30] "meatNAcleaver"                       
[31] "carjack"                             
[32] "chain"                               
[33] "contractor'sNAlevel"                 
[34] "railroadNAspikes"                    
[35] "stapler"                             
[36] "beerNAbottle"                        
[37] "unknownNAweapon"                     
[38] "binoculars"                          
[39] "bean-bagNAgun"                       
[40] "baseballNAbatNAandNAfireplaceNApoker"
[41] "straightNAedgeNArazor"               
[42] "gunNAandNAknife"                     
[43] "ax"                                  
[44] "brick"                               
[45] "baseballNAbat"                       
[46] "handNAtorch"                         
[47] "chainNAsaw"                          
[48] "gardenNAtool"                        
[49] "scissors"                            
[50] "pole"                                
[51] "pick-axe"                            
[52] "flashlight"                          
[53] "baton"                               
[54] "spear"                               
[55] "chair"                               
[56] "pitchfork"                           
[57] "hatchetNAandNAgun"                   
[58] "rock"                                
[59] "pieceNAofNAwood"                     
[60] "pipe"                                
[61] "glassNAshard"                        
[62] "motorcycle"                          
[63] "pepperNAspray"                       
[64] "metalNArake"                         
[65] "crowbar"                             
[66] "oar"                                 
[67] "macheteNAandNAgun"                   
[68] "tireNAiron"                          
[69] "airNAconditioner"                    
[70] "poleNAandNAknife"                    
[71] "baseballNAbatNAandNAbottle"          
[72] "fireworks"                           
[73] "pen"                                 
[74] "chainsaw"                            
[75] "gunNAandNAsword"                     
[76] "gunNAandNAcar"                       
[77] "pelletNAgun"                         
[78] "claimedNAtoNAbeNAarmed"              
[79] "incendiaryNAdevice"                  
[80] "samuraiNAsword"                      
[81] "bowNAandNAarrow"                     
[82] "gunNAandNAvehicle"                   
[83] "vehicleNAandNAgun"                   
[84] "wrench"                              
[85] "walkingNAstick"                      
[86] "barstool"                            
[87] "grenade"                             
[88] "BBNAgunNAandNAvehicle"               
[89] "waspNAspray"                         
[90] "airNApistol"                         
[91] "AirsoftNApistol"                     
[92] "baseballNAbatNAandNAknife"           
[93] "vehicleNAandNAmachete"               
[94] "iceNApick"                           
[95] "car,NAknifeNAandNAmace"              
[96] "bottle"                              
[97] "gunNAandNAmachete"                   
[98] "microphone"                          
[99] "knifeNAandNAvehicle"                 

My first attempt didn’t work as it didn’t get rid of the “” and instead replace all the blanks for everything, and it leads to things like airNApistol, knifeNAandNAvehicle and more.

The second attempt of removing “”

shootingsfix2 <- gsub("","NA",shootings$armed)
unique(shootingsfix2)
 [1] "NAgNAuNAnNA"                                                                                       
 [2] "NAuNAnNAaNArNAmNAeNAdNA"                                                                           
 [3] "NAtNAoNAyNA NAwNAeNAaNApNAoNAnNA"                                                                  
 [4] "NAnNAaNAiNAlNA NAgNAuNAnNA"                                                                        
 [5] "NAkNAnNAiNAfNAeNA"                                                                                 
 [6] "NA"                                                                                                
 [7] "NAsNAhNAoNAvNAeNAlNA"                                                                              
 [8] "NAvNAeNAhNAiNAcNAlNAeNA"                                                                           
 [9] "NAhNAaNAmNAmNAeNArNA"                                                                              
[10] "NAhNAaNAtNAcNAhNAeNAtNA"                                                                           
[11] "NAsNAwNAoNArNAdNA"                                                                                 
[12] "NAmNAaNAcNAhNAeNAtNAeNA"                                                                           
[13] "NAbNAoNAxNA NAcNAuNAtNAtNAeNArNA"                                                                  
[14] "NAuNAnNAdNAeNAtNAeNArNAmNAiNAnNAeNAdNA"                                                            
[15] "NAmNAeNAtNAaNAlNA NAoNAbNAjNAeNAcNAtNA"                                                            
[16] "NAsNAcNArNAeNAwNAdNArNAiNAvNAeNArNA"                                                               
[17] "NAlNAaNAwNAnNA NAmNAoNAwNAeNArNA NAbNAlNAaNAdNAeNA"                                                
[18] "NAfNAlNAaNAgNApNAoNAlNAeNA"                                                                        
[19] "NAgNAuNAnNAsNA NAaNAnNAdNA NAeNAxNApNAlNAoNAsNAiNAvNAeNAsNA"                                       
[20] "NAcNAoNArNAdNAlNAeNAsNAsNA NAdNArNAiNAlNAlNA"                                                      
[21] "NAcNArNAoNAsNAsNAbNAoNAwNA"                                                                        
[22] "NABNABNA NAgNAuNAnNA"                                                                              
[23] "NAmNAeNAtNAaNAlNA NApNAoNAlNAeNA"                                                                  
[24] "NATNAaNAsNAeNArNA"                                                                                 
[25] "NAmNAeNAtNAaNAlNA NApNAiNApNAeNA"                                                                  
[26] "NAmNAeNAtNAaNAlNA NAhNAaNAnNAdNA NAtNAoNAoNAlNA"                                                   
[27] "NAbNAlNAuNAnNAtNA NAoNAbNAjNAeNAcNAtNA"                                                            
[28] "NAmNAeNAtNAaNAlNA NAsNAtNAiNAcNAkNA"                                                               
[29] "NAsNAhNAaNArNApNA NAoNAbNAjNAeNAcNAtNA"                                                            
[30] "NAmNAeNAaNAtNA NAcNAlNAeNAaNAvNAeNArNA"                                                            
[31] "NAcNAaNArNAjNAaNAcNAkNA"                                                                           
[32] "NAcNAhNAaNAiNAnNA"                                                                                 
[33] "NAcNAoNAnNAtNArNAaNAcNAtNAoNArNA'NAsNA NAlNAeNAvNAeNAlNA"                                          
[34] "NArNAaNAiNAlNArNAoNAaNAdNA NAsNApNAiNAkNAeNAsNA"                                                   
[35] "NAsNAtNAaNApNAlNAeNArNA"                                                                           
[36] "NAbNAeNAeNArNA NAbNAoNAtNAtNAlNAeNA"                                                               
[37] "NAuNAnNAkNAnNAoNAwNAnNA NAwNAeNAaNApNAoNAnNA"                                                      
[38] "NAbNAiNAnNAoNAcNAuNAlNAaNArNAsNA"                                                                  
[39] "NAbNAeNAaNAnNA-NAbNAaNAgNA NAgNAuNAnNA"                                                            
[40] "NAbNAaNAsNAeNAbNAaNAlNAlNA NAbNAaNAtNA NAaNAnNAdNA NAfNAiNArNAeNApNAlNAaNAcNAeNA NApNAoNAkNAeNArNA"
[41] "NAsNAtNArNAaNAiNAgNAhNAtNA NAeNAdNAgNAeNA NArNAaNAzNAoNArNA"                                       
[42] "NAgNAuNAnNA NAaNAnNAdNA NAkNAnNAiNAfNAeNA"                                                         
[43] "NAaNAxNA"                                                                                          
[44] "NAbNArNAiNAcNAkNA"                                                                                 
[45] "NAbNAaNAsNAeNAbNAaNAlNAlNA NAbNAaNAtNA"                                                            
[46] "NAhNAaNAnNAdNA NAtNAoNArNAcNAhNA"                                                                  
[47] "NAcNAhNAaNAiNAnNA NAsNAaNAwNA"                                                                     
[48] "NAgNAaNArNAdNAeNAnNA NAtNAoNAoNAlNA"                                                               
[49] "NAsNAcNAiNAsNAsNAoNArNAsNA"                                                                        
[50] "NApNAoNAlNAeNA"                                                                                    
[51] "NApNAiNAcNAkNA-NAaNAxNAeNA"                                                                        
[52] "NAfNAlNAaNAsNAhNAlNAiNAgNAhNAtNA"                                                                  
[53] "NAbNAaNAtNAoNAnNA"                                                                                 
[54] "NAsNApNAeNAaNArNA"                                                                                 
[55] "NAcNAhNAaNAiNArNA"                                                                                 
[56] "NApNAiNAtNAcNAhNAfNAoNArNAkNA"                                                                     
[57] "NAhNAaNAtNAcNAhNAeNAtNA NAaNAnNAdNA NAgNAuNAnNA"                                                   
[58] "NArNAoNAcNAkNA"                                                                                    
[59] "NApNAiNAeNAcNAeNA NAoNAfNA NAwNAoNAoNAdNA"                                                         
[60] "NApNAiNApNAeNA"                                                                                    
[61] "NAgNAlNAaNAsNAsNA NAsNAhNAaNArNAdNA"                                                               
[62] "NAmNAoNAtNAoNArNAcNAyNAcNAlNAeNA"                                                                  
[63] "NApNAeNApNApNAeNArNA NAsNApNArNAaNAyNA"                                                            
[64] "NAmNAeNAtNAaNAlNA NArNAaNAkNAeNA"                                                                  
[65] "NAcNArNAoNAwNAbNAaNArNA"                                                                           
[66] "NAoNAaNArNA"                                                                                       
[67] "NAmNAaNAcNAhNAeNAtNAeNA NAaNAnNAdNA NAgNAuNAnNA"                                                   
[68] "NAtNAiNArNAeNA NAiNArNAoNAnNA"                                                                     
[69] "NAaNAiNArNA NAcNAoNAnNAdNAiNAtNAiNAoNAnNAeNArNA"                                                   
[70] "NApNAoNAlNAeNA NAaNAnNAdNA NAkNAnNAiNAfNAeNA"                                                      
[71] "NAbNAaNAsNAeNAbNAaNAlNAlNA NAbNAaNAtNA NAaNAnNAdNA NAbNAoNAtNAtNAlNAeNA"                           
[72] "NAfNAiNArNAeNAwNAoNArNAkNAsNA"                                                                     
[73] "NApNAeNAnNA"                                                                                       
[74] "NAcNAhNAaNAiNAnNAsNAaNAwNA"                                                                        
[75] "NAgNAuNAnNA NAaNAnNAdNA NAsNAwNAoNArNAdNA"                                                         
[76] "NAgNAuNAnNA NAaNAnNAdNA NAcNAaNArNA"                                                               
[77] "NApNAeNAlNAlNAeNAtNA NAgNAuNAnNA"                                                                  
[78] "NAcNAlNAaNAiNAmNAeNAdNA NAtNAoNA NAbNAeNA NAaNArNAmNAeNAdNA"                                       
[79] "NAiNAnNAcNAeNAnNAdNAiNAaNArNAyNA NAdNAeNAvNAiNAcNAeNA"                                             
[80] "NAsNAaNAmNAuNArNAaNAiNA NAsNAwNAoNArNAdNA"                                                         
[81] "NAbNAoNAwNA NAaNAnNAdNA NAaNArNArNAoNAwNA"                                                         
[82] "NAgNAuNAnNA NAaNAnNAdNA NAvNAeNAhNAiNAcNAlNAeNA"                                                   
[83] "NAvNAeNAhNAiNAcNAlNAeNA NAaNAnNAdNA NAgNAuNAnNA"                                                   
[84] "NAwNArNAeNAnNAcNAhNA"                                                                              
[85] "NAwNAaNAlNAkNAiNAnNAgNA NAsNAtNAiNAcNAkNA"                                                         
[86] "NAbNAaNArNAsNAtNAoNAoNAlNA"                                                                        
[87] "NAgNArNAeNAnNAaNAdNAeNA"                                                                           
[88] "NABNABNA NAgNAuNAnNA NAaNAnNAdNA NAvNAeNAhNAiNAcNAlNAeNA"                                          
[89] "NAwNAaNAsNApNA NAsNApNArNAaNAyNA"                                                                  
[90] "NAaNAiNArNA NApNAiNAsNAtNAoNAlNA"                                                                  
[91] "NAANAiNArNAsNAoNAfNAtNA NApNAiNAsNAtNAoNAlNA"                                                      
[92] "NAbNAaNAsNAeNAbNAaNAlNAlNA NAbNAaNAtNA NAaNAnNAdNA NAkNAnNAiNAfNAeNA"                              
[93] "NAvNAeNAhNAiNAcNAlNAeNA NAaNAnNAdNA NAmNAaNAcNAhNAeNAtNAeNA"                                       
[94] "NAiNAcNAeNA NApNAiNAcNAkNA"                                                                        
[95] "NAcNAaNArNA,NA NAkNAnNAiNAfNAeNA NAaNAnNAdNA NAmNAaNAcNAeNA"                                       
[96] "NAbNAoNAtNAtNAlNAeNA"                                                                              
[97] "NAgNAuNAnNA NAaNAnNAdNA NAmNAaNAcNAhNAeNAtNAeNA"                                                   
[98] "NAmNAiNAcNArNAoNApNAhNAoNAnNAeNA"                                                                  
[99] "NAkNAnNAiNAfNAeNA NAaNAnNAdNA NAvNAeNAhNAiNAcNAlNAeNA"                                             

My second attempt made it where everything is just NA values and nothing more.

Removing the “”

shootings_clean <- shootings |>
  select(race, armed) |>
  mutate(armed = trimws(armed)) |>   #(got the code trimws from this website I linked on the bottom )
  filter(!is.na(armed), armed != "")

Using the code triws I was able to get rid of the ““. And I just filter as another layer to get rid of the possible na that could be in the variable.

unique(shootings_clean$armed)
 [1] "gun"                              "unarmed"                         
 [3] "toy weapon"                       "nail gun"                        
 [5] "knife"                            "shovel"                          
 [7] "vehicle"                          "hammer"                          
 [9] "hatchet"                          "sword"                           
[11] "machete"                          "box cutter"                      
[13] "undetermined"                     "metal object"                    
[15] "screwdriver"                      "lawn mower blade"                
[17] "flagpole"                         "guns and explosives"             
[19] "cordless drill"                   "crossbow"                        
[21] "BB gun"                           "metal pole"                      
[23] "Taser"                            "metal pipe"                      
[25] "metal hand tool"                  "blunt object"                    
[27] "metal stick"                      "sharp object"                    
[29] "meat cleaver"                     "carjack"                         
[31] "chain"                            "contractor's level"              
[33] "railroad spikes"                  "stapler"                         
[35] "beer bottle"                      "unknown weapon"                  
[37] "binoculars"                       "bean-bag gun"                    
[39] "baseball bat and fireplace poker" "straight edge razor"             
[41] "gun and knife"                    "ax"                              
[43] "brick"                            "baseball bat"                    
[45] "hand torch"                       "chain saw"                       
[47] "garden tool"                      "scissors"                        
[49] "pole"                             "pick-axe"                        
[51] "flashlight"                       "baton"                           
[53] "spear"                            "chair"                           
[55] "pitchfork"                        "hatchet and gun"                 
[57] "rock"                             "piece of wood"                   
[59] "pipe"                             "glass shard"                     
[61] "motorcycle"                       "pepper spray"                    
[63] "metal rake"                       "crowbar"                         
[65] "oar"                              "machete and gun"                 
[67] "tire iron"                        "air conditioner"                 
[69] "pole and knife"                   "baseball bat and bottle"         
[71] "fireworks"                        "pen"                             
[73] "chainsaw"                         "gun and sword"                   
[75] "gun and car"                      "pellet gun"                      
[77] "claimed to be armed"              "incendiary device"               
[79] "samurai sword"                    "bow and arrow"                   
[81] "gun and vehicle"                  "vehicle and gun"                 
[83] "wrench"                           "walking stick"                   
[85] "barstool"                         "grenade"                         
[87] "BB gun and vehicle"               "wasp spray"                      
[89] "air pistol"                       "Airsoft pistol"                  
[91] "baseball bat and knife"           "vehicle and machete"             
[93] "ice pick"                         "car, knife and mace"             
[95] "bottle"                           "gun and machete"                 
[97] "microphone"                       "knife and vehicle"               

I did this to check if I was able to remove the blank. And by taking a look at it, I couldn’t see “” meaning I have succeeded in removing it.

summary(shootings_clean)
     race              armed          
 Length:6213        Length:6213       
 Class :character   Class :character  
 Mode  :character   Mode  :character  

This gave me a summary of the two variables I am using.

shootings_clean<-shootings_clean |>
 mutate(is_armed = ifelse(armed == "unarmed", "NO", "YES"))

This code allows me to make a graph. If I don’t make it where it is yes or no if the person is armed or not, the code wouldn’t allow me to make a graph.

race_armed_counts <- shootings_clean |>
  group_by(race, armed) |>
  summarise(count = n(), .groups = "drop")

race_armed_counts
# A tibble: 244 × 3
   race  armed          count
   <chr> <chr>          <int>
 1 ""    Airsoft pistol     1
 2 ""    BB gun             1
 3 ""    Taser              3
 4 ""    ax                 3
 5 ""    baseball bat       2
 6 ""    baton              2
 7 ""    beer bottle        1
 8 ""    chain saw          1
 9 ""    crossbow           3
10 ""    crowbar            1
# ℹ 234 more rows

This gave me a count to all the weapons that were showed in the data set. And made it easier for me to see how often a certain weapon was at the scene.

ggplot(shootings_clean, aes(x = race, fill = is_armed)) +
  geom_bar() +
  labs(
    title = "Distribution of Armed vs Unarmed by Race",
    x = "Race",
    y = "Count",
  ) +
  theme_minimal()

Finally, this is the graph that I have created.It will allow me to answer my question.

Conclusion

The largest number of fatal shootings involved individuals identified as White (W), followed by Black (B) and Hispanic (H) individuals.While fatal shootings of individuals identified as Asian (A), Native American (N), Other (O), or Unknown(not being showed on the x-axis) occur at significantly lower frequencies in this dataset.And this graph does give us an answer to if there any connection of the race of the person with them being armed. The blue in the graph is yes where they are armed while red is that they are unarmed. Most of the people that died were armed with a few being unarmed and is reflected on the graph. For the Native Americans and other races, they were always armed. And for the Asians, they were mostly always armed. And there is a decent amount of people being unarmed for the Whites and Blacks. Meaning yes there is a connection of the race of the person with them being armed. There could be some implications to the dataset which will affect the answer of the question. There is a chance where certain groups are “over-represented,” or there is bias towards certain groups.And we need to know where these people got shot and use it as it could affect the data as well. For the future, I need to use other variables as well instead of just two. I didn’t use the variables flee and signs of mental illness and they could be helpful to answer the question. And I need to watch out for geographic trend as well.

References

https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/trimws