## Purpose:

Ranks the indices of a series in descending or ascending order.

## Syntax:

series

-

A series or table.

order

-

Optional. An integer or string, the sort direction.

 0 or "descend" : descending order (default) 1 or "ascend" : ascending order

## Returns:

Series that contains the indices (i.e. sample numbers) of the sorted input series.

## Example:

W1: {6, 2, 4, 1, 8}

returns the series {5, 1, 3, 2, 4}, the indices of W1 in descending order.

## Example:

W3: sort(W1)

W4: W1[W2]

Both W3 and W4 contain the series {8, 6, 4, 2, 1}, the sorted values of W1 in descending order.

## Example:

a = int(rand(5)*10);

c = a[b, ..];

Series a contains a 5x5 table of random integers. Series c sorts all the columns of a based on the sorted values of the first column of a.

## Remarks:

As shown in the last example, GRADE is useful for sorting series or tables based on a root series.

GRADE performs a stable sort where the original order of duplicate values is preserved. See SORT for more details.