[R] R-ish challenge for dependent ranking

ivo welch ivowel at gmail.com
Mon Aug 25 17:10:36 CEST 2008


Dear R wizards:  First, thanks for the notes on SQL.  These pointers
will make it a lot easier to deal with large data sets.   Sorry to
have a second short query the same day.  I have been staring at this
for a while, but I cannot figure out how to do a dependent ranking the
R-sh way.

ds= data.frame( xn=rnorm(32), yn=rnorm(32), zn=rnorm(32) )
ds$drank1group= as.integer((rank( ds$xn )-1)/4)  # ok, the first set
of 8 groups, each with 4 elements

ds$drank2.bydrank1group= ??? ## here I want within each drank1group
the rank based on yn (from 1 to 4)

something like "by(ds,drank1group, rank(ds$yn))".  obviously, this
neither works nor has same dimensional output.

of course, there is a really simple, clever way to do this in
R...except that it totally eludes me.  before I start writing a hand
iterating function, could someone please let me know how to do this?

regards,

/iaw



More information about the R-help mailing list