SORTN Function

Sorts a matrix by its rows.

Usage

i = SORTN(a)

Input Parameters

aA matrix of real numbers or strings.

Returned Value

i—An array of indices, such that a(i,*) is the sorted version of a. Sorting is lexicographical, and it is stable if the matrix does not contain strings.

Keywords

Ncolumns—Integer specifying that sorting be lexicographical on a(*,0:Ncolumns–1) and where the other columns are ignored. This keyword is ignored for string data or if the Manyequal keyword is set.

Descending—If set, the first column is prioritized by descending order.

Columns—Vector of positive integers specifying that sorting be lexicographical on a(*,Columns), where other columns are ignored. Columns need not be in any particular order, and if Columns(i)<0, descending order is used for column |Columns(i)|. If for example Columns=[–2,0] then sorting is first by descending order in column 2 and then by ascending order in column 0, and any other columns are ignored. This keyword is ignored for string data or if the Manyequal keyword is set.

Manyequal—If set, this invokes an algorithm which is faster for matrices where many of the rows are equal, and though the notion of 'many' varies with both dimensions of the input matrix, a good rule-of-thumb is that the Manyequal keyword is most useful when the number of unique rows is less than 10% of the total. This algorithm is always used for string input.

Note:

For generally better performance on numerical data, the default SORTN algorithm changed as of PV-WAVE 10.1. Use the Manyequal keyword to invoke the algorithm available prior to PV-WAVE 10.1. However, unlike the new algorithm, the older algorithm does not always preserve the original relative order of equal rows.

Examples

a = BYTSCL( RANDOMU(seed,9,2), Top=5 )
PM, a
b = SORTN( a )
PM, b
PM, a(b,*)
i = SORTN(a,Columns=[1,0])
PM, a(i,*)

See Also

SORT, UNIQUE, UNIQN