I have a given dataset with 8 variables
Var1 <- c(1,0,1,0,1)
Var2 <- c(1,0,1,0,1)
Var3 <- c(1,1,1,0,1)
Var4 <- c(1,0,1,1,1)
Var5 <- c(1,0,0,0,1)
Var6 <- c(1,0,1,0,1)
Var7 <- c(1,1,1,0,1)
Var8 <- c(0,0,0,0,1)
DF <- data.frame(Var1, Var2, Var3, Var4, Var5, Var6, Var7, Var8)
DF
which results in:
Var1 Var2 Var3 Var4 Var5 Var6 Var7 Var8
1 1 1 1 1 1 1 1 0
2 0 0 1 0 0 0 1 0
3 1 1 1 1 0 1 1 0
4 0 0 0 1 0 0 0 0
5 1 1 1 1 1 1 1 1
Each object represents a person, who participated in a study. And each person is capable of giving multiple answers. Person 1 for example has answered every single question, except question 8 (Var8 = 0) with "yes" (1). Person 2 only answered question 3 and 7 with "yes" etc..
I want to find the frequency distribution for every single combination of answers for the variables Var1 to Var6. In other words, how many people have answered only Var1 and Var2, how many answered Var1 and Var4, how many Var5 and Var6 and Var7 with a yes (1), and so on..
So far I tried:
DF %>%
filter(across(Var1:Var3) == 1) %>%
count(Var1, Var2, Var3)
for one of the variable combinations (Var1, Var2, Var3).
Is there a way to calculate this, other than going through every single combination by hand and select/filter/count them? Thanks in advance.