Skip to content

computing ranks in subgroups

2 messages · RINNER Heinrich, Brian Ripley

#
Dear R-users!

I am using R 1.0.0 and Windows NT 4.0. I want to compute ranks for the
values of a variable, in several subgroups of a data.frame.
Currently I use:
val=c(10,3,9,3,5,1,7))
group val
1     A  10
2     A   3
3     B   9
4     A   3
5     B   5
6     B   1
7     A   7
group val valgroupranks
1     A  10           4.0
2     A   3           1.5
4     A   3           1.5
7     A   7           3.0
3     B   9           3.0
5     B   5           2.0
6     B   1           1.0
This seems to work, but I wonder if there is a more "natural" (simple?) way
to do that?

Heinrich..
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Mon, 29 May 2000, RINNER Heinrich wrote:

            
Look at by():
x$group: A
[1] 4.0 1.5 1.5 3.0
------------------------------------------------------------ 
x$group: B
[1] 3 2 1
A1  A2  A3  A4  B1  B2  B3 
4.0 1.5 1.5 3.0 3.0 2.0 1.0