I want to collect members of one column in my data frame where it has all the values in another column.
The sample dataset looks like this:
df <- structure(list(ID=c('a','a','a','a','b','b','c','c','d','d','d','d','e','e','f','f','f','g','h','h','h','h','i','i','i','i'),
A1=c('g1','g1','g1','g1','g1','g1','g1','g1','g2','g2','g2','g2','g2','g2','g2', 'g2','g2','g3', 'g3','g3','g3','g3','g3','g3', 'g3','g3'),
number=c(1, 2,3,4,1,2,1,3,1,2,3,4,2,3,2,3,4,1,1,2,3,4,1,2,3,4)),
class = "data.frame", row.names = c(NA,-26L))
As a result I want to know which groups have exactly all of the given values in the column number.
df.result<- structure(list(ID=c('a','b','c','d','e','f','g','h','i'),
A1=c('g1','g1','g1','g2','g2','g2','g3','g3','g3'),
all.numbers=c('yes','no','no','yes','no','no','no','yes','yes')),
class = "data.frame", row.names = c(NA,-9L))
Thanks