• esProc
Tutorial
Function Reference
Sample Program
Code Reference
User Reference
External Library Guide
Data File Tool Manual
DQL Tutorial
Cluster Server Manager Manual
SPL Command Executor Manual
• YModel
User Reference
JSON-style Parameter Guide
• Official Website

# ranks()

Here’s how to use ranks() functions.

## A .ranks( x )

Description:

Get the rankings of members of sequence A.(x).

Syntax:

 A.ranks(x) Equivalent to A. (x).ranks()

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.

Option:

 @z Return a ranking according to members sorted in descending order. Here “z” is in lowercase. @i Deduplicate sequence A.(x) before getting the rankings. @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 A A sequence

Return value:

An integer sequence made up of rankings of members of sequence A.(x).

Example:

 A 1 =demo.query("select * from SCORES where SUBJECT='English'") 2 =A1.ranks(SCORE) [21,19,13,27,11,23,13,9,25,1,17,7,5,1,21,19,13,27,11,23,13,9,25,1,17,7,5,1];Rank members in ascending order 3 =A1.ranks@z(SCORE) [7,9,13,1,17,5,13,19,3,25,11,21,23,25,7,9,13,1,17,5,13,19,3,25,11,21,23,25];Rank members in descending order 4 =A1.ranks@i(SCORE) [9,8,6,12,5,10,6,4,11,1,7,3,2,1,9,8,6,12,5,10,6,4,11,1,7,3,2,1]; rankings with duplicates removed 5 =A1.(SCORE).ranks() Same requirement as that in A2 6 =A1.ranks@s(SCORE) [21.5,19.5,14.5,27.5,11.5,23.5,14.5,9.5,25.5,2.5,17.5,7.5,5.5,2.5,21.5,19.5,14.5,27.5,11.5,23.5,14.5,9.5,25.5,2.5,17.5,7.5,5.5,2.5]; get averages for duplicate rankings and then return the final result

Related function:

A.ranks()

## A .ranks()

Description:

Compute the ranking of each member in a sequence.

Syntax:

A.ranks()

Note:

The function obtains the ranking of each member in sequence A and returns a sequence composed of rankings of the members, which by default are sorted in ascending order.

Parameter

 A A sequence

Option:

 @z Return a ranking according to members sorted in descending order. Here “z” is in lowercase. @i Deduplicate sequence A before getting the rankings. @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.

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.ranks() [3,2,5,6,8,7,3,1]; rank members in ascending order 3 =A1.ranks@z() [5,7,4,3,1,2,5,8]; rank members in descending order 4 =A1.ranks@i() [3,2,4,5,7,6,3,1]; rankings with duplicates removed 5 =A1.ranks@s() [3.5,2.0,5.0,6.0,8.0,7.0,3.5,1.0]; get averages for duplicate rankings and then return the final result

Related function:

A.ranks(x)

Here’s how to use read() function.

Description:

Read contents of a file and return result as strings.

Syntax:

Note:

The function reads in the contents of file f from the bth byte to the eth byte and returns the substring.

Parameter:

 f A file b A byte number beginning from 0 e A byte number beginning from 0

Option:

 @n Return the contents of the file object f as a string sequence; each row is corresponding to a member. @v Return a sequence as the corresponding data type. The combined use of this option and @n is acceptable @0 Read the file once and return the total number of bytes in it; used for test

Return value:

A string

Example:

 A 1 =file("D:/score.txt") 2 =A1.read() Read the contents of file object score.txt as a string 3 =A1.read@n() With @n option, read and concatenate each line in the text file into a string and return it as a member of the resulting sequence 4 =file("D:/tmp2.txt") 5 =["Lucy","98"] By default Lucy is a string and 98 is an integer 6 =A4.write(A5) 7 =A4.read@nv() With @nv options, return a sequence consisting of rows of different data types 8 =A1.read@b() Read the text file as the binary blob data 9 =file("atoz.txt").read() Read in content of atoz.txt 10 =file("atoz.txt").read(2:7) Read in content of atoz.txt from the second byte to the 7 byte 11 =file("atoz.txt").read@0() Use @0 option to return the total number of byte in atoz.txt; the result is 26

Related function: