# Correlation between numerical and categorical data in R [duplicate]

I have a dataset with over 20 variables. Some of them are numerical and some of them are categorical:

C          <- c(4, 8.5, 2, 5, 6)
N          <- c(0.4, 0.1, 0.5, 1.2, 1.1)
moisture   <- as.factor(cbind("dry","dry","dry","wet","wet"))
vegetation <- as.factor(cbind("forest", "wetland", "field", "forest", "wetland"))
df         <- data.frame(C,N, moisture,vegetation)


I want to know the pairwise correlation between each of these variables. I found two solutions for this: rcorr() and hetcor(). While rcorr gives me Pearsons's product-moment correlation or Spearman's rho rank correlation including p-values, hetcor() offers me the discrimination into polyserial and polychoric correlations, but no p-values.

I would use rcorr with Pearson which has the advantage of also including p-values, but I am not sure if it qualifies for this sort of data. Can I still talk of correlations in this case or do I need to talk about significance of association? If I use hetcor I seem to gain the advantage of it being applicable for categorical data, but I don't get the p-values.

## marked as duplicate by Silverfish, gung♦ r StackExchange.ready(function() { if (StackExchange.options.isMobile) return; $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() { var$hover = $(this).addClass('hover-bound'),$msg = $hover.siblings('.dupe-hammer-message');$hover.hover( function() { $hover.showInfoMessage('', { messageElement:$msg.clone().show(), transient: false, position: { my: 'bottom left', at: 'top center', offsetTop: -7 }, dismissable: false, relativeToBody: true }); }, function() { StackExchange.helpers.removeMessages(); } ); }); }); Jan 5 '16 at 3:45

• Ok, thanks for your replies. What I take from this is that neither hetcor() nor rcorr make sense in my case and that I should rather work with a series of linear models or using η from ANOVA following your link. Therefor this post seems to be missleading and wrong or is it still possible to use Pearson even though there is no hierarchy in my categorial data? – mace Dec 21 '15 at 23:03
From hetcor documentation you can learn that