REORDER

Purpose:

Arranges a series or table based on a list of indices.

Syntax:

REORDER(series, indices)

series

-

Any series or multi-column table.

indices

-

Series of indices (i.e. sample numbers) on which to reorder.

Returns:

A series or table.

Example:

W1: gnorm(10, 1)

W2: grade(w1)

W3: reorder(W1, w2)

W3: w3 == sort(w1)

 

W1 contains 10 random values.

 

W2 returns the indices of W1 sorted from the maximum to the minimum value.

 

W3 looks up the values of W1 using the indices in W2.

 

W4 compares the result in W3 to the descending sort of W1. The results are equivalent.

Example:

W1: {2, 5, 9, 1, 3}

W2: reorder(W1, {3, 1, 2, 4, 5})

 

W2 contains the series {9, 2, 5, 1, 3}. The same result can be achieved with array addressing:

 

W3: W1[{3, 1, 2, 4, 5}]

Example:

To reorder a table based upon the values in the first column:

 

W1: {{2, 5, 3},

     {1, 1, 1}, 

     {4, -1, 0}} 

 

reorder(W1, grade(col(W1, 1), 1))

 

returns the array:

 

{{1, 1, 1}, 

 {2, 5, 3}, 

 {4, -1, 0}} 

 

This is equivalent to:

 

W1[grade(col(w1, 1), 1), ..]

 

or

 

W1[grade(W1[.., 1], 1), ..]

 

Example:

W1: 10 * ravel(1..12, 4)

W2: {{1, 2, 4},

     {2, 1, 3},

     {3, 3, 2},

     {4, 4, 1}}

W3: reorder(W1, W2)

 

W1 contains a 3x4 array.

 

W2 contains a 3x4 array of indices.

 

W3 looks up the values of W1 at the indices contained in W2. Each column of the index series of W2 looks up values in the corresponding column of W1. The resulting array is:

 

W4 == {{10, 60, 120},

       {20, 50, 110},

       {30, 70, 100},

       {40, 80,  90}}

Remarks:

REORDER uses a 1-based index series to look up the values of a series or array.

 

For multi-column inputs, the indices of each column of indices are used to look up the values of the corresponding column in series.

 

REORDER is similar to LOOKUP but much faster on larger series.

 

The results produced by REORDER can also be achieved by array addressing. See .. (Range Specifier) for more details on array addressing.

See Also:

.. (Range Specifier)

GRADE

LOOKUP

SORT

XYLOOKUP