A Sidhu A Sidhu - 5 months ago 51
R Question

How to find correlation coefficients for non-numeric variables

Species Gender Weight Corneal Diameter Avg
Great Grey M 971 19.5
Great Grey F 1209 19.0
Great Grey M 952 20.5
Great Grey F 1793 20.5
Snowy M 1658 22.0
Snowy F 1899 22.75
Snowy F 1975 24.50
Snowy M 1646 23.00

Okay so I have this data set. I want to see if there is a correlation between Male Corneal Diameter Average vs. Female Corneal Diameter Average. I'm not sure how I would do this in R. I tried to create a subset for males and females and then use cor(x, y) to get the correlation coefficient but it's not working. Any help would be appreciated!

Answer Source

Use Spearman rank correlation. If x and y are the two vectors which may or may not be numeric.

cor(rank(x), rank(y))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download