[R] is there a way to do dense rank in R

Matt Shotwell shotwelm at musc.edu
Fri Jul 2 04:37:43 CEST 2010


> x <- c(5,7,7,9)
> rank(unique(x))[match(x, unique(x))]
[1] 1 2 2 3

On Thu, 2010-07-01 at 21:30 -0400, Suresh Singh wrote:
> I have not been able to find a way to do dense rank in R
> 
> Here is an example of what I need
> 
> rank() gives the following
> 
> 5 rank 1
> 7 rank 2
> 7 rank 2
> 9 *rank 4*
> 
> but I want
> 
> 5 rank 1
> 7 rank 2
> 7 rank 2
> 9 *rank 3*
> *
> *
> thanks
> SS
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
-- 
Matthew S. Shotwell
Graduate Student
Division of Biostatistics and Epidemiology
Medical University of South Carolina
http://biostatmatt.com



More information about the R-help mailing list