sortRowIndices function

Syntax

  • float[] sortRowIndices(array)

Parameters

  1. array—(float[], string[])
    Array to be sorted.

Description

The sortRowIndices function returns the indices of sorted rows in array. The size of the returned index array equals the number of rows of array. Duplicate rows are sorted in the order of appearance.

array =                                                [4,0,1;
                                                        2,1,9;
                                                        1,3,0;
                                                        2,1,0]
 
sortRowIndices(array)                                  [2,3,1,0]
 
array[sortRowIndices(array),0:nColumns(array)-1]       [1,3,0;
                                                        2,1,0;
                                                        2,1,9;
                                                        4,0,1]

Related

Example

Sort rows by column precedence

const a = [4,0,1;
           2,1,9;
           1,3,0;
           2,1,0]
	  
sortRows(a,columnPrecedence) = a[sortRowIndices(a[0:nRows(a)-1,columnPrecedence]),0:nColumns(a)-1]

// sort by column 1
const b = sortRows(a,1) // [4,0,1;
                        //  2,1,9;
                        //  2,1,0;
                        //  1,3,0]

// sort by column 1, then column 0, then column 2
const c = sortRows(a,[1,0,2]) // [4,0,1;
                              //  2,1,0;
                              //  2,1,9;
                              //  1,3,0]