table rank rows, table rank selected rows
This function ranks the rows according to ransorting criteria defined, i.e. columns and applicable sorting options. Ranking is a meaningful alternative to identify the ordering of the data without phyically rearranging the rows. Specific rules are provided for ranking multiple entries which are equal.
Indirect parameter passing is disabled
This function provides a table context for partial table specifications with table name and row number for selected function parameters
2-4
No. | Type | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
1. input |
string | Name of existing table | ||||||||||
Opt. 2. code |
expression :string |
Expression to select rows Applicable to table rank selected rows only: | ||||||||||
2 / 3. input |
table column | Destination column for rank numbers See table columns as function parameters for general ruling for this parameter.
| ||||||||||
Opt. 3 / 4. input |
table columns | Columns considered for ranking order If more than 1 column is specified, then the first column has the highest ranking priority, with additional columns considered
if the prior comparison resulted in equal contents, e.g. ranking by last name followed by first name.
| ||||||||||
Opt. 4 / 5 input |
string | Ranking option See sorting options for available values. Default value: alphabetic | ||||||||||
Opt. 5 / 6 input |
numeral | Ranking scheme for equal values One of following:
Default value: 123 | ||||||||||
Opt. 6 / 7 input |
numeral | Rank starting number Normally, ranking begins with 1. In some cases, it is useful to apply cascaded rankings on different rows on the same table, and you want to continue with the next lower ranking number in the 2nd or further ranking rounds. See code example below. Default value: 1 |
Type | Description |
---|---|
numeral | Next further rank number Useful for casecaded ranking (provide as last parameter in the next call) |
table initialize( animals,
{ { Animal, Leg Count },
{ ant, 6 }, { mouse, 4 }, { spider, 8 }, { octopus, 8 }, { bird, 2 },
{ tick, 8 }, { human, 2 }, { ape, 4 }, { lobster, 8 }, { snake, 0 },
{ cat, 4 }, { ape, 2 }, { spider, 6 }, { fly, 6 } } );
echo("Ranked all animals with more than 4 legs from Z-A, then those with 2 legs from A-Z (cascaded ranking)");
a[] = table rank selected rows( animals, [Leg Count]>4 , Rank, Animal, alphabetic down, 112 );
table rank selected rows( animals, [Leg Count]<=2, Rank, Animal, alphabetic, 112, a[] );
table list ( animals );
table initialize( names, { Name, Benita, Allen, Dominique, Andy, Benita, BENITA, Dominique, Michele } );
echo("Different ranking schemes on names using alphabetic ordering, ignoring case, start with rank 0:");
table process ( names, for all ( { 123, 213, 112, 113, 223 }, scheme[] )
{
table rank rows( names, str(scheme[]), Name, alphabetic ignore case, scheme[], 0 );
} );
table list ( names );
Ranked all animals with more than 4 legs from Z-A, then those with 2 legs from A-Z (cascaded ranking)
0 : Animal | Leg Count | Rank
1 : ant | 6 | 6
2 : mouse | 4 |
3 : spider | 8 | 2
4 : octopus | 8 | 3
5 : bird | 2 | 8
6 : tick | 8 | 1
7 : human | 2 | 9
8 : ape | 4 |
9 : lobster | 8 | 4
10 : snake | 0 | 10
11 : cat | 4 |
12 : ape | 2 | 7
13 : spider | 6 | 2
14 : fly | 6 | 5
Different ranking schemes on names using alphabetic ordering, ignoring case, start with rank 0:
0 : Name | 123 | 213 | 112 | 113 | 223
1 : Benita | 2 | 4 | 2 | 2 | 4
2 : Allen | 0 | 0 | 0 | 0 | 0
3 : Dominique | 5 | 6 | 3 | 5 | 6
4 : Andy | 1 | 1 | 1 | 1 | 1
5 : Benita | 3 | 3 | 2 | 2 | 4
6 : BENITA | 4 | 2 | 2 | 2 | 4
7 : Dominique | 6 | 5 | 3 | 5 | 6
8 : Michele | 7 | 7 | 4 | 7 | 7