In R, I have a dataset with 10 columns of interest. These columns are binary, where 1 means true and 2 means false. I need to subset the data to find the number of times at which only 2 columns equal 1, only 3 columns equal 1, etc. The issue- I don't care which 3 equal 1, I just need data on how many times it occurs that any combination of 3 equals 1.
This is the only way I have been able to find this, but I have to write all this code for each combination, and this is way too tedious with 1023 possible combinations.
a1x3 <- filter(ALL_STATES_TBL, ace3 == "1" & ace4 == "2" & ace5 == "2" & ace6 == "2" & ace7 == "2" & ace8 == "2" & ace9 == "2")
a1x3t <- filter(a1x3, ace1 == "3")
a1x3tt <- filter(a1x3, ace1 == "4")
a1x3 <- rbind(a1x3t, a1x3tt)
Any help would be greatly appreciated! [Also, code is written this way because ace1 has 4 options instead of 2].