Perform Action to all possible combinations of columns

69 Views Asked by At

I´m new to R so forgive me if the question is quite mundane. I have a table with categorical variables as columns. I need to calculate the contingency coefficient between every possible combination of two columns.

To calculate the contingency coefficient I use ContCoef() from the DescTools. ContCoef() expects two columns as inputs.

ContCoef(data[,1], data[,2], correct = TRUE)
1

There are 1 best solutions below

0
Kevin On

I managed to get it working using PairApply:

library(DescTools)
PairApply(comp_testdata,FUN=function(x,y) cor(as.numeric(x),as.numeric(y),method='pearson'),symmetric=TRUE)