ranks()

Read(2733) Label: get, ranking,

Description:

Get the rankings of members of a sequence.

Syntax:

A.ranks(x)

 

Note:

The function computes expression x over each member of sequence A to return the rankings of members of sequence A.(x), which by default is sorted in ascending order.

Parameter:

A

A sequence

x

An expression; cannot be omitted when A is a table sequence or a record sequence

Option:

@z

Return a ranking in descending order

@i

Deduplicate sequence A.(x) before getting the rankings

@s

Perform average operation on rankings of duplicate members and return the final result, which could contain non-integers.

Return value:

An integer sequence

Example:

When A is a sequence:

 

A

 

1

=[2,1,3,4,8,5,2,0]

 

2

=A1.ranks()

[3,2,5,6,8,7,3,1]; rankings in ascending order.

3

=A1.ranks@z()

[5,7,4,3,1,2,5,8]; rankings in descending order.

4

=A1.ranks@i()

[3,2,4,5,7,6,3,1]; remove duplicate members and then get rankings.

5

=A1.ranks@s()

[3.5,2.0,5.0,6.0,8.0,7.0,3.5,1.0]; compute average of rankings of duplicate members and then get rankings. That is, there are two members with value 2 and their rankings are 3 and 4 respectively and the result of average operation is (3+4)/2=3.5; so ranking of 2 in the sequence is 3.5.

 

When A is a table sequence or a record sequence:

 

A

 

1

=demo.query("select top 10 * from SCORES where SUBJECT='English'")

2

=A1.ranks@z(SCORE)

Get rankings of SCORE values in descending order and return [4,5,6,1,8,3,6,9,2,10] .

3

=A1.ranks@zi(SCORE)

First remove duplicate SCORE values and then get rankings in descending order, and return [4,5,6,1,7,3,6,8,2,9] .

4

=A1.ranks@zs(SCORE)

First compute average of rankings of duplicate members and then get rankings, and return [4.0,5.0,6.5,1.0,8.0,3.0,6.5,9.0,2.0,10.0], that is – there are two members having value 75 and their rankings are 6 and 7 respectively, and result of average operation is (6+7)/2=6.5; so ranking of 75 in the sequence is 6.5.