let's say that I have a data frame like below. That is, each person has multiple diagnoses (dx).
person dx1 dx2 dx3 dx4
A Y Y N N
B N N Y Y
C Y Y N Y
...
Now, for each of the above dx, how could I generate a tabulation as below, to output the counts for each possible combination of dx. The following counts are made up for demonstration purpose. For the first line of record for example, it would mean 2 persons have dx1 (but nothing else), 1 person has both dx1 and dx2.
N dx1 dx2 dx3 dx4
dx1 2 1 0 0
dx2 0 1 1 0
dx3 1 2 1 1
dx4 0 0 1 0
Your kind help is greatly appreciated!
Best regards, Jie