Message-ID: <200504191547.j3JFldk6007610@erdos.math.unb.ca>
Date: 2005-04-19T15:47:39Z
From: Rolf Turner
Subject: Ranking within a classification variable.
Suppose I have a data frame with two columns ``district'' and
``score'' --- score is numeric; district may be considered
categorical.
I wish to append to this data frame a third column whose entries are
the ranks of ``score'' ***within*** district.
I've tried fiddling about with tapply() and by() but the result is a
list whose i-th component consists of the ranks of the scores within
the i-th district. I then have trouble figuring out how to put these
results into a column of the data frame in the proper order.
Is there a slick-quick-sexy way of doing this (without resorting to
looping)? Am I missing something obvious?
Thanks for any help bestowed.
cheers,
Rolf Turner
rolf at math.unb.ca