ptop()

Here’s how to use ptop() function.

A .ptop()

Description:

Get the ordinal numbers of the n smallest members in a sequence.

Syntax:

A.ptop(n,x)

Note:

The function sorts members of sequence A according to expression x and returns a sequence comprising the ordinal numbers of the n smallest members in the given sequence. List both if the smallest member and the largest member are the same.

Parameter:

A

A sequence

x

Sorting expression, which is parsed as ~ when the parameter is absent

n

An integer that should always be present; thefuncion returns null when the parameter is 0

Option:

@1

Return a single value if n is ±1

@0

Do not ignore null members

Return value:

A sequence composed of ordinal numbers of specified members

Example:

 

A

 

1

[a,c,e,g,f,d,b]

 

2

=A1.ptop(3,~)

[1,7,2]

3

=A1.ptop(3)

Same as A2, as x is not supplied

4

=demo.query("select * from EMPLOYEE")

 

5

=A4.ptop(3,HIREDATE)

[8,18,203]

6

=A1.ptop(-1)

7

=A1.ptop@1(-1)

8

[a,c,e,g,f,d,b,a]

 

9

=A8.ptop(1,~)

[1,8]

10

=[1,5,1,7,2,null,4,3].ptop@0(2)

[6,3,1]

Related function:

A.pos()

A.sort()

A.pos(x)

A.psort()

A.top()