It is not the best thing to use the same correlation (or covariance) calculation between categorical and continuous data. You should use pearson's correlation for continuous data and spearman's correlation for categorical data. These two methods might produce similar results in some cases.
for covariance try:
cov(data_set,method='spearman')
or
cov(data_set,method='pearson') #this is the default
depending on the method you want to choose according to your data type.
For the correlation replace the cov()
function with cor()
.
The factor variable you have needs to be converted to numeric beforehand:
gender <- as.numeric(gender)
UPDATE:
Just to make sure that you are calculating correlations in a correct way I believe you should probably convert all of your variables into one type i.e. all continuous or all categorical. The typical way is to bin your continuous data into categorical (yes you might lose some information value, but in general you will get what you want) and then use the spearman correlation/covariance matrix. This way at least your calculations are consistent and you can do everything in one go using cov()
or cor()
cov
(even with method =spearman
) is not correct. Spearman correlation is for continuous and ordinal data, and gender doesn't belong in either of these! – Suren