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
You'll need to create an index to represent the order of category. Then sort based on the priority of your categories and dedup by Name and Course.
library(tidyverse)
#create index to sort by
index.df <- data.frame("Cateory" = c('PT',"DI","GT","SY"), "Index" = c(1,2,3,4))
#join to orig dataset
data <- left_join(data, index.df, by = "Cateory")
#sort by index, dedup with Name and Course
data %>% arrange(Index) %>% group_by(Name,Course) %>%
distinct(Name,Course, .keep_all = TRUE) %>% select(-Index)