[R] getting rank order

Warnes, Gregory R gregory_r_warnes at groton.pfizer.com
Fri Jan 25 02:52:27 CET 2002


Jay,

I believe that 'order' will do what you want:

> motivations <- c(3,5,2,4,1)
> order(motivations)
[1] 5 3 1 4 2

So, if you a data frame or a matrix of 'motivations' with one row per
subject and one column per 'pick', you should be able to do

ranks <- apply( motivation.matix, 1, order )

I hope this helps.

-Greg


> -----Original Message-----
> From: Jay Pfaffman [mailto:pfaffman at relaxpc.com]
> Sent: Thursday, January 24, 2002 6:35 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] getting rank order
> 
> 
> I'm doing a study where people place a deck of cards in a certain
> order.  It's sufficient to assume that their colors & each has a
> number (it's actually about attributes of hobbies).  I'd like to look
> for patterns in how they've arranged the deck.  For each subject I
> have a list like 3,5,2,4,1, indicating that (s)he chose 3 first, then
> 5, then 2. . . .
> 
> I think what I first need to do is to make a variable for each card
> with the rank given to each card, so the above list should be
> transformed to something like
> 
> card1 card2 card3 card4 card5
>   5     3     1     4     2
> 
> I've RTFMed on sort and rank.  I can't find an elegant solution in
> either a spreadsheet or R.  I'm about to give up and do it by hand.
> 
> I thought that something like
> 
>    for (i in 1:25) ranks [1,as.integer(motivations[1,i])] <- i
> 
> might do it (and I'd add another loop to replace the 1's above), but
> I've been unsuccessful.
> 
> Anyway, solutions to that problem are welcome, as are suggestions
> about how to start looking at those data once I've done that.
> 
> Thanks.
> 
> P.S.  I asked some weeks ago for pointers to some "R cookbooks."
> Several people pointed out the "user contributed" documents.  I'm not
> sure how I missed them, but I did.  They've been quite helpful.  Also,
> I was able to find a copy of MASS in the library (not sure why I
> didn't think to look there sooner).  I'll soon break down and buy it.
> Thanks to all those who helped.
> 
> -- 
> Jay Pfaffman                           pfaffman at relaxpc.com
> +1-415-821-7507 (H)                    +1-415-810-2238 (M)
> http://relax.ltc.vanderbilt.edu/~pfaffman/
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
> -.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
> _._._._._._._._._
> 


LEGAL NOTICE
Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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