I have a R data like the following:
id = c(1,1,1,2,2,4,4,3,3,3)
buyernames = c("ann","ann","bo","celine","celine","mary","lily","john","john","john")
data = cbind(id,buyernames)
#id buyernames
#[1,] "1" "ann"
#[2,] "1" "ann"
#[3,] "1" "bo"
#[4,] "2" "celine"
#[5,] "2" "celine"
#[6,] "4" "mary"
#[7,] "4" "lily"
#[8,] "3" "john"
#[9,] "3" "john"
#[10,] "3" "john"
ID is numeric. What I want to know is if there are ids that are associated with different names. If so, what are the ids and names.
desired output - a data like the following:
id buyernames
1 ann
1 bo
4 mary
4 lily
Any insight would be greatly appreciated.
The
uniquefunction can eliminate duplicate rows, and theduplicatedfunction can be used to identify duplicate ids after duplicate rows are removed. So, the following should work: