Here’s how to use rank() function.
Description:
Compute the ranking of a specified value in a sequence.
Syntax:
A.rank(y)
Note:
The function returns the ranking of a specified value y in sequence A, which by default is sorted in ascending order.
Options:
@z |
Return a ranking according to members sorted in descending order. Here “z” is in lowercase. |
@i |
Deduplicate sequence A before getting y’s ranking. |
@s |
Perform average operation for each of the duplicate ranking and return the result, which could contain non-integers. Take the sequence [3,2,6,6,9] for example, a default ranking is [2,1,3,3,5]; but with @s option, the ranking becomes [2.0,1.0,(3+4)/2,(3+4)/2,5.0] after we get averages for the two duplicates. |
Parameters:
A |
A sequence |
y |
A member of sequence A |
Return value:
An integer sequence composed of rankings of sequence A’s members
Example:
|
A |
|
1 |
=[2,1,3,4,8,5,2,0] |
|
2 |
=A1.rank(6) |
8; a ranking according to ascendingly ordered members |
3 |
=A1.rank@z(6) |
2; a ranking according to descendingly ordered members |
4 |
=A1.rank@i(2) |
3; deduplicate the sequence before finding the ranking |
5 |
=A1.rank@s(2) |
3.5; get averages for duplicate rankings and then return the final result |
Related functions:
Description:
Get the ranking of a certain member in the computed sequence.
Syntax :
A.rank(y,x) |
Equivalent to A.(x).rank(y) |
Note:
The function computes expression x over each member of sequence A and returns the ranking of a given value y in sequence A.(x). By default the sequence members are sorted in ascending order.
Options:
@z |
Return a ranking according to members sorted in descending order. Here “z” is in lowercase. |
@i |
Deduplicate sequence A.(x) before getting y’s ranking. |
@s |
Perform average operation for each of the duplicate ranking and return the result, which could contain non-integers. Take the sequence [3,2,6,6,9] for example, a default ranking is [2,1,3,3,5]; but with @s option, the ranking becomes [2.0,1.0,(3+4)/2,(3+4)/2,5.0] after we get averages for the two duplicates. |
Parameters:
x |
An expression according to which sequence A is computed. |
y |
A member of sequence A or a value for comparing members of sequence A.(x). |
A |
A sequence. |
Return value:
The ranking of a given member
Example:
|
A |
|
1 |
=demo.query("select * from SCORES where SUBJECT='English'") |
|
2 |
=A1.rank(90,SCORE) |
23; a ranking according to ascendingly ordered members |
3 |
=A1.rank@z(90,SCORE) |
5; a ranking according to descendingly ordered members |
4 |
=A1.rank@i(90,SCORE) |
10; the ranking with duplicate(s) removed |
5 |
=A1.(SCORE).rank(90) |
23 |
6 |
=A1.rank@s(90,SCORE) |
23.5; get averages for duplicate rankings and then return the final result |
Related functions:
Description:
An interative loop for numbering records according to the values of certain fields.
Syntax:
rank(F;Gi,…)
Note:
The function performs a loop operation to number records from 1 according to the value of Gi field. With the same Gi field value, records having the same F field value will be given the same sequence number. When the value of F field changes, the sequence number for the corresponding record is the previous sequence number plus the number of the records with that sequence number. When the value of Gi field changes, start a new round of the numbering process.
Parameters:
F |
Field name |
Gi |
Field name |
Returned value:
Integer
Example:
|
A |
|
1 |
=demo.query("select * from SCORES ") |
|
2 |
=A1.derive(rank(STUDENTID;CLASS):F1) |
|