1

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)
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Kevin
  • 47
  • 6
  • 1
    Welcome to Stack Overflow. It's easier to help if you [make this question reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by including a small representative dataset in a plain text format - for example the output from `dput(data)`, if that is not too large. – neilfws May 18 '23 at 03:28
  • Welcome to SO! :) The website of the `DescTools` package lists the `PairApply` function. So something similar to `PairApply(data, ContCoef, symmetric = TRUE)` could work. But again hard to tell without an minimum reproducible example. – flxflks May 18 '23 at 06:24

1 Answers1

0

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)
Kevin
  • 47
  • 6