Okay so I have a large collection of data I'm trying to analyze. It contains ~2 million police reports with information such as jurisdiction, type of offense, race, age, etc. My end goal is to determine the top 20 jurisdictions with the most reports, and then chart only the entries from those locations in various ways.
top20 <- police %>%
group_by(JURISDICTION) %>%
tally(sort=TRUE) %>%
filter(row_number() <= 20)
I'm using this to tally up the totals in each jurisdiction and then trim down to the top 20 entries. What I'd like to have happen next is, using each of the entries in column one of this top20 data.frame, create a new data frame with the name of the locality, as well as all the entries from police with a matching jurisdiction.
I've been experimenting with something along the lines of:
for (i in 1:20) {
assign(paste(top20[i,1]),
filter(police, JURISDICTION == top20[i,1]))
}
which does create data frames with the correct names, but the second portion isn't reading correctly and it's just creating blank data frames at the moment. Any advice on how to streamline this would be appreciated. I'm very capable of just making each frame individually, but if I can do it succinctly I'll be more satisfied.