Here is my example data set:
Name Course Cateory
1: Jason ML PT
2: Jason ML DI
3: Jason ML GT
4: Jason ML SY
5: Ja
I would suggest using the dplyr
package for this
See below:
require(dplyr)
data %>%
mutate(
Category_factored=as.numeric(factor(Category,levels=c('PT','DI','GT','SY'),labels=1:4))
) %>%
group_by(Name,Course) %>%
filter(
Category_factored == min(Category_factored)
)
In case you are new to R, install dplyr using install.packages('dplyr')