Skip to content

Instantly share code, notes, and snippets.

@dwillis
Last active March 7, 2022 20:07
Show Gist options
  • Save dwillis/f7e65e253c0255224264ac60994c669d to your computer and use it in GitHub Desktop.
Save dwillis/f7e65e253c0255224264ac60994c669d to your computer and use it in GitHub Desktop.
Calculating police shootings' gender percentage with guns
# create dataframe of all shootings by gender
all_police_shootings_by_gender <- fatal_police_shootings %>%
group_by(gender) %>%
summarise(count=n()) %>%
arrange(desc(count))
# create separate dataframes for each gender
all_shootings_men <- all_police_shootings_by_gender %>%
filter(gender == 'M')
all_shootings_women <- all_police_shootings_by_gender %>%
filter(gender == 'F')
# create dataframe of all shootings by gender where victim has gun
gun_police_shootings_by_gender <- fatal_police_shootings %>%
filter(armed_clean == "gun") %>%
group_by(gender) %>%
summarise(count=n()) %>%
arrange(desc(count))
# create separate dataframes for each gender
all_shootings_men_with_gun <- gun_police_shootings_by_gender %>%
filter(gender == 'M')
all_shootings_women_with_gun <- gun_police_shootings_by_gender %>%
filter(gender == 'F')
# calculate percentages for both using the count column - I'll leave that to you.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment