Let's say I have the following dataframe:
users <- data.frame(name = c('John', 'John', 'Bob'), age = c(18, 18, 28), country = c('Brazil', 'Brazil', 'US'), Grade = c('A', 'B', 'C'))
If I run the code below, only the first and third row will be kept.
users %>% distinct(name, age, country, .keep_all = TRUE)
However, I would like to keep the second John. Whenever there is a duplicate, the one with the lower grade should be chosen. Or maybe the one in which the grade column has a string containing a substr or something like this. How can I do this in a Tidyverse-way?