There are two common ways of describing a permutation using an Integer vector
ranks. The first uses ranks:
holds the index value to which the
th data element should be moved in order to sort the data; in other words its rank in the sorted order. The second uses indices:
holds the current index value of the data element which would occur in
th position in sorted order. For example, given the values
to be sorted in ascending order, the ranks would be
and the indices would be
The m01d- functions generate ranks, and the m01e- functions require indices to be supplied to specify the re-ordering. However if it is desired simply to refer to the data in sorted order without actually re-ordering them, indices are more convenient than ranks (see
Section 10).
nag_make_indices (m01zac) can be used to convert ranks to indices, or indices to ranks, as the two permutations are inverses of one another.
None.
Not applicable.
None.
The example program reads a matrix of real numbers and prints its rows with the elements of the 1st column in ascending order as ranked by
nag_rank_sort (m01dsc). The program first calls
nag_rank_sort (m01dsc) to rank the rows, and then calls
nag_make_indices (m01zac) to convert the rank vector to an index vector, which is used to refer to the rows in sorted order.