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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Tyler Ritchie
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?

-Tyler

[1] view-source:http://svn.r-project.org/R/trunk/src/library/base/R/rank.R

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Question about use of sort.list(sort.list(x)) in rank.r

William Dunlap

> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf
> Of Tyler Ritchie
> Sent: Tuesday, October 16, 2012 2:23 PM
> To: [hidden email]
> 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]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.