[R] Question about use of sort.list(sort.list(x)) in rank.r

William Dunlap wdunlap at tibco.com
Tue Oct 16 23:37:40 CEST 2012


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Tyler Ritchie
> Sent: Tuesday, October 16, 2012 2:23 PM
> To: r-help at r-project.org
> Subject: [R] Question about use of sort.list(sort.list(x)) in rank.r
> 
> I was looking at rank() and I came across:
> 
> ...
> "first" = sort.list(sort.list(xx)), ...
> 
> line 32 of rank.r [1]
> 
> sort.list(x) returns the indices of the values of x in ascending (by
> default) order. So sort.list(sort.list(x)) returns the same list.
> 
> So, what am I missing here?

An example:
  > x <- c("E", "B", "C", "A", "F", "G", "D")
  > s <- sort.list(x)
  > s <- as.matrix(sort.list(x))
  > for(i in 2:5) s <- cbind(s, sort.list(s[,ncol(s)]))
  > data.frame(x, s)
    x X1 X2 X3 X4 X5
  1 E  4  5  4  5  4
  2 B  2  2  2  2  2
  3 C  3  3  3  3  3
  4 A  7  1  7  1  7
  5 F  1  6  1  6  1
  6 G  5  7  5  7  5
  7 D  6  4  6  4  6

Note how function(x)sort.list(sort.list(x)) is idempotent, but not
sort.list itself.
  
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> 
> -Tyler
> 
> [1] view-source:http://svn.r-project.org/R/trunk/src/library/base/R/rank.R
> 
> 	[[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.




More information about the R-help mailing list