rank()

Read(696) Label: rank,

Here are how to use rank() functions.

A.rank( y )

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.

Option:

@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.

Parameter:

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 function:

A.rank(y,x)

A.rank( y,x )

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.

Option:

@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.

Parameter:

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 function:

A.rank(y)

rank()

Description:

Perform an iterative calculation in a loop function to number records according to values of a specific field.

Syntax:

rank(F;Gi,…)

Note:

The function performs a loop operation to number records from 1 according to values of Gi field. With the same Gi field value, records having same F field value will be given 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. Note that the function does not sort records.

Parameter:

F

Field name

Gi

Field name

Return value:

Integer

Example:

 

A

 

1

=demo.query("select  SUBJECT,STUDENTID,SCORE from SCORES where CLASS='Class one' order by SUBJECT,SCORE desc")

Get score information of students in class one and sort result by SUBJECT in ascending order and by SCORE in descending order

2

=A1.derive(rank(SCORE;SUBJECT): RANKING)

Get ranking of scores for each subject – same rank for same score and a tied result takes up a rank, and store result ranks under RANKING field