dat <- as.data.frame(replicate(100,sample(c(0,1),100,replace=TRUE)))
I want to create a 100 by 100 matrix with the correlation coefficients between these binary variables as entries.
If the variables were continuous, then I would have used cor()
to create the matrix. I am not sure if cor()
with Pearson as the method is reasonable. If not, say I could find a function fn()
to calculate the correlation between a pair of binary vectors. What is an efficient way to construct the 100 by 100 matrix?