[R] Partial sort?

Bill.Venables at csiro.au Bill.Venables at csiro.au
Thu Jan 15 00:19:16 CET 2009


Specifying a partial sort allows you to specify a re-arrangement of the data into groups where all the values in any group are guaranteed to be at least as large as any value in the previous group.  Within the groups themselves, though, the values are not sorted.

Here is an example:

> x <- round(runif(20), 2)
> x
 [1] 0.18 0.23 0.03 0.97 0.41 0.87 0.79 0.16 0.11 0.85 0.96 0.74 0.56
[14] 0.34 0.75 0.03 0.34 0.39 0.01 0.71

> x <- sort(x, partial = seq(5, 20, 5))

> matrix(x, nrow=5)
     [,1] [,2] [,3] [,4]
[1,] 0.01 0.18 0.71 0.79
[2,] 0.11 0.23 0.74 0.96
[3,] 0.03 0.34 0.56 0.85
[4,] 0.03 0.34 0.41 0.87
[5,] 0.16 0.39 0.75 0.97
>  

Notice that the first five values (first column) are the 5 lowest, the next 5 are the next lowest, and so on.  (Notice also that in this example the last group consists of the 20th value by itself, which is therefore the maximum for the entire vector in the partially sorted version.)

Bill Venables
http://www.cmis.csiro.au/bill.venables/ 


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of rkevinburton at charter.net
Sent: Thursday, 15 January 2009 8:59 AM
To: r-help at r-project.org
Subject: [R] Partial sort?

This is definitely a newbie question but from the documentation I have not been able to figure out what the partial sort option on the sort method does. I have read and re-read the documentation and looked at the examples but for some reason it doesn't register. Would someone attempt to explain what sort with a non-null partial array of indices does?

Thank you.

Kevin

______________________________________________
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