[R] Spearman rank-order correlation matrix
John Fox
jfox at mcmaster.ca
Tue May 7 16:19:52 CEST 2002
Dear Russell,
At 04:52 PM 5/6/2002 -0700, Russell Senior wrote:
>I"ve got a data frame with a selection of columns I want to compute a
>rank-order correlation matrix from without disturbing the original
>data frame.
>
> foo[,c("a","b","d","f","g")]
>
>What I wanted to do, intuitively, was:
>
> > cor(rank(foo[,c("a","b","d","f","g")]))
>
>but rank in that context ranks all of the values from the matrix
>together as one long vector. I want the columns (and their names) to
>be preserved, just replacing the value with its rank. What is the
>most direct way to get what I want?
Try
cor(apply(foo[,c("a","b","d","f","g")], 2, rank))
I hope that this helps,
John
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list