I have a set of binary variables (with the values of 0 and 1) and I want to create a two-way count table that summarizes the counts of cooccurrence of pairs of variables (i.e., both of them have the value of 1). Here is an example dataset:
mm <- matrix(0, 5, 6)
m <- 2
n <- 2
df <- data.frame(apply(mm, c(1,2), function(x) sample(c(0,1),1)))
colnames(df) <- c("Horror", "Thriller", "Comedy", "Romantic", "Sci.fi", "gender")
In the end, I would like to have the table that counts the cooccurrence of Horror(=1) and gender(=1), Thriller(=1) and gender(=1), Comedy(=1) and gender(=1), Romantic(=1) and gender(=1), and sci.fi(=1) and gender(=1).