psort()

Here’s how to use psort() function.

A.psort()

Description:

Get the original positions of the sorted members of a sequence.

Syntax:

A.psort (x)

A.psort(xi,...)

Note:

The function sorts members of sequence A according to the value of expression x and returns their sequence numbers before they are sorted.

Parameters:

A

A sequence

x

The sorting expression

xi

If there are multiple sorting expressions, they can be written as xi,.., a compound expression consisting of multiple expressions. The function sorts members by xi,… sequentially in ascending order by default. - xi means sorting in descending order

Options:

  @m  Perform parallel algorithm to enhance performance of handling data-intensive or computation-intensive tasks.

@z

Sort a sequence in descending order and return the position of a member in the original sequence

@0

Put records with null values at the end

Return value:

A sequence composed of the sequence numbers of all the members in a given sequence before they are sorted by expression x.

Example:

 

A

 

1

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

 

2

=A1.psort(~)

[1,7,2,6,3,5,4]

3

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

 

4

=A3.psort(DEPT,BIRTHDAY)

A3 is sorted in ascending order by DEPT first, and then in descending order by BIRTHDAY.

5

=A3.psort@m(DEPT,BIRTHDAY)

Use @m opton to increase performance of big data handling.

6

=A1.psort@z(~)

[4,5,3,6,2,7,1]

7

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

 

8

=A7.psort(~)

[4,1,7,2,6,3,5]

9

=A7.psort@0(~)

[1,7,2,6,3,5,4]

Related functions:

A.pos()

A.sort()

A.pos(x)

A.swap(p,q)

A.rvs()