Here is my sample data frame. The actual data frame has a lot more groups and 9 conditions in each group.
df <- data.frame(
Group = c('A','A','B','B','B','C','C','C','D','D','D','D'),
Condition = c('cond2', 'cond3','cond1','cond2','cond3','cond1','cond2','cond3', 'cond1','cond2','cond3','cond4'),
Value = c(0,0,0,1,0,0,0,1,0,1,0,0)
)
> df
Group Condition Value
1 A cond2 0
2 A cond3 0
3 B cond1 0
4 B cond2 1
5 B cond3 0
6 C cond1 0
7 C cond2 0
8 C cond3 1
9 D cond1 0
10 D cond2 1
11 D cond3 0
12 D cond4 0
Question I: groups match the conditions
Get the groups that exactly have cond1 == 0, cond2 == 1, and cond3 == 0 (in this case, group B meets the criteria).
The desired output:
Group Condition Value
1 B cond1 0
2 B cond2 1
3 B cond3 0
Question II: groups contain the condtions
Get the groups that contain cond1 == 0 and cond2 == 1, other conds could be 1 or 0 (in this case, group B and group D should be selected. Please note that group C doesn't meet the criterion because it has cond2 == 0).
Group Condition Value
1 B cond1 0
2 B cond2 1
3 B cond3 0
4 D cond1 0
5 D cond2 1
6 D cond3 0
7 D cond4 0