Skip to content
Prev 166773 / 398503 Next

pmax and sort?

Here are a couple of quick examples that may help:
[1]  1  2  3  4  5  6  7  8  9 10
[1] 10  9  8  7  6  5  4  3  2  1
[1] 10  9  8  7  6  6  7  8  9 10
[1] 1 2 3 4 5 5 5 5 5 5

In the first example with pmax, there are 2 vectors being compared (10-1, 1-10), so first 10 is compared to 1 and since 10 is larger it is the first element of the returned vector, then 9 is compared to 2 and 9 becomes the second element, this continues till the 10th comparison is 1 vs. 10 and 10 is the final element.  The second (pmin) example shows the recycling, each of the numbers 1-10 is compared to the number 5, in each case the smaller of the pair is returned (1-4 for the first 4 elements, then 5 for the rest).

Hope this helps,