I know this question has been asked in all sorts of variants, but I could not extract the solution to my specific problem. Given a data frame like this:
a <- c(rep("A", 3), rep("B", 3), rep("C",2))
b <- c(1,1,2,4,1,1,2,2)
df <-data.frame(a,b)
This results in:
a b
1 A 1
2 A 1
3 A 2
4 B 4
5 B 1
6 B 1
7 C 2
8 C 2
I want to only keep row number 3 (A 2) and 4 (B 4). I have tried all combinations of unique(), duplicated() and !duplicated() or distinct, but could not get the desired result, since there seems to be no combination of logical TRUE and FALSE that only filters out the non-duplicated rows. Thanks in advance!