[R] getting rank order

Jonathan Baron baron at cattell.psych.upenn.edu
Fri Jan 25 01:27:01 CET 2002


>From: Jay Pfaffman <pfaffman at relaxpc.com>

>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 think what you want is order()
If you have something like m1:

3 5 2 4 1
1 2 3 4 5
5 4 3 2 1
..

Then 
t(apply(m1,1,order))
gives you
     [,1] [,2] [,3] [,4] [,5]
[1,]    5    3    1    4    2
[2,]    1    2    3    4    5
[3,]    5    4    3    2    1

You need the t() if you want it laid out this way.  Otherwise it
comes out in columns instead of rows.

Jon
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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