'R how to detect first last name with different ID?

ID <- c(1,2,2,3,3,3,4,5)
Firstname <- c("A","B","B","C","C","C","D","A")
Lastname <- c("F","G","G","H","H","H","I","F")
df <- data.frame(ID,Firstname,Lastname)

I want to find A F who has ID no 1 and 5. In my real data, it's a long list and there are some persons who use different ID no. with the same name. How would you find out the row index of these people? Any suggestion will be appreciated.



Solution 1:[1]

Getting the result as a list:

subset(aggregate(ID~Firstname + Lastname, unique(df), length), ID > 1)[1:2]

  Firstname Lastname
1         A        F

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1