Is it possible in R to subset a dataframe by more than one factor, all at
once?
For instance, I have the dataframe:
p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 pred
1 0 1 0 0 0 0 0 0 0 0 0.5862069
4 0 0 0 0 0 0 0 0 0 1 0.5862069
5 0 0 0 0 0 0 1 0 0 0 0.5862069
6 0 0 0 0 0 0 0 1 0 0 0.5862069
7 0 0 1 0 0 0 0 0 0 0 0.5862069
9 0 0 0 0 1 0 0 0 0 0 0.5862069
20 0 1 1 0 0 0 0 0 0 0 0.5862069
22 0 1 0 0 1 0 0 0 0 0 0.5862069
24 0 1 0 0 0 0 1 0 0 0 0.5862069
25 0 1 0 0 0 0 0 1 0 0 0.5862069
27 0 1 0 0 0 0 0 0 0 1 0.5862069
If I want to subset only those points that have p4 = 1, I do:
And that's fine. Now suppose I want to subset those that not only have p4
= 1, but also p6 = 1.
I tried subset(data,p4 == 1 && p6 == 1) or subset(data,p4==1 & p6==1).