I created a simple data.frame:
data.frame(a = rep(LETTERS[1:4], each=4),
b = c(sample(6,4),sample(6,4),sample(6,4),sample(6,4)))
a b
1 A 6
2 A 4
3 A 2
4 A 3
5 B 5
6 B 1
7 B 3
8 B 6
9 C 2
10 C 3
11 C 5
12 C 1
13 D 4
14 D 5
15 D 1
16 D 3
How can I keep only those rows of the data.frame where the number in column b appears in all 4 letters of column a? So, for instance, the number 3 in column b appears for A, B, C and D in column a and should therefore be kept.
Here is a slightly different approach making use of recursive intersection.