I have a dataframe that looks like so:
year <- year
month <- c(1,1,1,1,1,2,2,2,3,3)
county <- c("Upshur", "Upshur", "Upshur", "Collin","Collin","Upshur","Upshur", "Collin","Upshur","Collin")
citation <- c(1,0,1,1,1,0,1,0,1,1)
df <- data.frame(year, month, county, citation)
# year month county citation
#1 2007 1 Upshur 1
#2 2007 1 Upshur 0
#3 2007 1 Upshur 1
#4 2007 1 Collin 1
#5 2007 1 Collin 1
#6 2007 2 Upshur 0
#7 2007 2 Upshur 1
#8 2007 2 Collin 0
#9 2007 3 Upshur 1
#102007 3 Collin 1
#...
Where I have individual incidents of police stops that state whether the stop ended in citation or ticket based on whether citation has a 1 or 0. What I am aiming to do is aggegate this data into a smaller dataframe where frequency of tickets and citations is stated for each county in each month. Basically, something that would look like so:
# year month county citations_given warnings_given
2007 1 Upshur 2 1
2007 1 Collin 2 0
2007 2 Upshur 1 0
2007 2 Collin 0 1
2007 3 Upshur 1 0
2007 3 Collin 1 0
...
Any suggestions would be appreciated!