[R] Ranking correlation with R

Joshua Wiley jwiley.psych at gmail.com
Fri Apr 9 18:53:39 CEST 2010


>> cor() requires numeric data.  To use it in this case, you would need
>> to come up with rankings based on the position for each file name, and
>> use those pairs of numbers with cor().
>
> One possible source for such numbers would be row.names(dfrm) since by
> default (assuming they are in a data.frame) row.names are an ascending
> series of integers, but one could also number them by appending a
> colrankn=1:nrow(dfrm).

What about this?

x <- c("A","C","B")
y <- c("A","B","C")
ranks <- match(y,x)

> ranks
[1] 1 3 2

> cor(seq_along(x), ranks)
[1] 0.5

It seems like as long as both sets of filenames contain exactly the
same names, that should work.

>
> David Winsemius, MD
> West Hartford, CT



-- 
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/



More information about the R-help mailing list