[R] Ranking within a classification variable.

From: Rolf Turner <rolf_at_math.unb.ca>
Date: Wed 20 Apr 2005 - 01:47:39 EST

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@math.unb.ca

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Apr 20 01:53:42 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:17 EST