Partial sort?
Duncan Murdoch wrote:
rkevinburton at charter.net wrote:
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?
It guarantees that those particular indices are sorted correctly, but doesn't guarantee anything else. For example,
> x <- 10:1 > sort(x, partial=1)
guarantees that the first entry in x (i.e. 10) is placed correctly, but nothing else, and the result is: [1] 1 9 8 7 6 5 4 3 2 10
Oops, that's wrong. It's entry 1 of the result which will be placed correctly. This example shows the difference: > x <- rep(1:3, 4) + rep(1:4/10, each=3) > x [1] 1.1 2.1 3.1 1.2 2.2 3.2 1.3 2.3 3.3 1.4 2.4 3.4 > sort(x, partial=2) [1] 1.1 1.2 1.3 1.4 2.2 3.2 3.1 2.3 3.3 2.1 2.4 3.4 Duncan Murdoch