I have the following data frame
library(dplyr)
ReportNumber<-c("19062167","19062167","19062167","19062822","19062822")
UCR_casetype<-c("Homicide","Homicide","Assault","Rape","Rape")
(df<-data.frame(ReportNumber,UCR_casetype))
ReportNumber UCR_casetype
1 19062167 Homicide
2 19062167 Homicide
3 19062167 Assault
4 19062822 Rape
5 19062822 Rape
The UCR_casetype is a way to classify crimes which has a hierarchy where Homicde>Rape>Assault. and I used the following to introduce levels into the UCR_casetype variable
df$UCR_casetype<-factor(df$UCR_casetype,
levels = c("Assault","Rape","Homicide"),ordered=TRUE)
What I want is to obtain the row that has the highest level under the UCR_casetype variable grouped by ReportNumber so that the resulting data frame looks like the following
ReportNumber UCR_casetype
1 19062167 Homicide
4 19062822 Rape
I tried this however, it does not work
df%>%group_by(ReportNumber)%>%
filter(max(UCR_casetype))