Suppose I have a data frame in the following form:
N1 N2 N3 N4 N5 N6
1 0 0 1 0 0
0 1 0 1 0 1
1 1 1 0 0 1
0 0 0 1 1 0
1 1 0 0 0 1
I would like to write a function that transform the above data frame to a contingency table like this:
(N2=0,N3=0) (N2=0,N3=1) (N2=1,N3=0) (N2=1,N3=1)
N5=0 1 0 2 0
N5=1 1 0 0 1
where I can specify what variables constitute the column and row. If possible, a function where I can substitute different data frame into it as well. Thanks!