I have such a dataframe:
KEY C1 C2 C3 C4
A 0 0 1 0
B 0 0 1 0
C 0 1 1 0
D 0 0 1 0
E 1 0 1 0
F 1 0 0 0
G 0 1 0 0
H 0 0 1 0
I 0 1 1 0
J 1 0 0 1
and would like to build this kind of matrix with only two values "1" being in the two variables.
I would not like to count rows where there are more then two values like:
KEY C1 C2 C3 C4
L 1 0 1 1
or less then two:
M 1 0 0 0
Output should be frequency table.
C1 C2 C3 C4
C1 3 0 1 1
C2 0 3 2 0
C3 1 2 7 0
C4 1 0 0 1
There may be more variables up to C20 and of course more rows. Thanks for helping me out!
G 0 1 0 0? By trying with your conditiondf2 <- df1[rowSums(df1[-1])==2,], I am not getting the expected result you showed. May be you need to look at your conditions.