ptop()

Here’s how to use ptop() function.

A .ptop()

Description:

Get the sequence 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 sequence numbers of the n smallest members in the given sequence. List both if the smallest member and the largest member are the same.

Parameters:

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

Options:

@1

Return a single value if n is ±1

Return value:

A sequence composed of sequence 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]

Related functions:

A.pos()

A.sort()

A.pos(x)

A.psort()

A.top()