2.2.3.74 wsort


Contents

Brief Information

Sort worksheet based on selected columns

Additional Information

X-Function not designed for Auto GetN Dialog.

Command Line Usage

1. wsort descending:=1; 
2. wsort descending:=1 bycol:=2 c1:=1 c2:=3; 
3. wsort bycol:=1 irng:=(2[5]:3[8],5[5]:6[8]);
4. wsort bycol:=1 irng:=(1:2,4:end);

X-Function Execution Options

Please refer to the page for additional option switches when accessing the x-function from script

Variables

Display
Name
Variable
Name
I/O
and
Type
Default
Value
Description
Worksheet to do sorting w

Input/Output

Worksheet

<active>

Specified worksheet to sort

Sort By Column bycol

Input

int

1

Specified the column data as the sort criteria. It is used when you want to sort worksheet by one column.

Decending or ascending descending

Input

int

0

Specified sorting by descending or ascending order. 0 = Ascending, 1 = Descending, 2 = Categorical Ascending, 3 = Categorical Descending

sort numeric_suffix sortnumeric

Input

int

0

Whether to Sort by Numeric Suffix

Nested Sort Columns nestcols

Input

vector

<optional>

Indices of columns used as sorting criteria. It is used when you want to sort worksheet by multiple columns

Note:: When nestcols is used,
  • The order variable is need to be used at the same time and order variable size need to be set to match nestcols (refer to Sample1 as below)
  • the variables bycol, descending, sortnumeric etc. cannot be used.
Sort Orders order

Input

vector

<optional>

sorting order index:

  • 0 descending
  • 1 ascending
  • 4 case sensitive
  • 8 numeric suffix (sort by Numeric Suffix)
  • 32 categorical descending
  • 33 categorical ascending
Note:
  • Its size should match the one of Nested Sort Columns.
  • The order variable is a bit combination option. If need to sort by 1 (ascending) and 8 (numeric suffix) simultaneously, you can set it to 9 (1 & 8), (refer to Sample2 as below)
Column From c1

Input

int

1

Start index of columns selected for sorting.

Column To c2

Input

int

0

End index of columns selected for sorting.

Row From r1

Input

int

1

Start index of rows selected for sorting.

Row To r2

Input

int

0

End index of rows selected for sorting

Missing is Largest missing

Input

int

0

Whether the missing value as largest.

Range to Sort irng

Input

range

<optional>

Specified ranges to sort. The range can be non-contiguous. If it has an effective value, c1, c2, r1, r2 will be ignored.

Description

This function is used to sort the worksheet by some column bycol (as index). Or nested sorted by some columns nestcols, then we can also set descending or ascending by each column order. We can specified the range(start row, end row, start column, end column or range variable irng) to sort. We can also sort by numeric suffix column(as index).

Examples

/*
This example uses the wsort X-Function to perform nested sorting. The data 
will be reordered so that the height column is in descending order. If there 
are multiple rows with the same height, these rows will be sorted by the 
weight column in ascending order.
1. Import the sample data into a book in Origin;
2. Sort the data with the wsort X-Function.
*/
//Create a new workbook
newbook result:=bkname$;	
//Import a file
path$ = system.path.program$ + "Samples\Statistics\";
fname$ = path$ + "body.dat";
impasc;

dataset sbc = {4, 5}; //Select the columns for the primary sort and the secondary sort
dataset sodr= {0, 1}; //Select the sort orders: col(4)--descending, col(5)--ascending
wsort nestcols:=sbc order:=sodr; //Perform the nested sorting

Sort this table:

2020.11.24 Mr. Mercedes S1E7
2020.11.25 Mr. Mercedes S1E10
2020.11.25 Mr. Mercedes S1E9
2020.11.24 Mr. Mercedes S1E8

To be:

2020.11.24 Mr. Mercedes S1E7
2020.11.24 Mr. Mercedes S1E8
2020.11.25 Mr. Mercedes S1E9
2020.11.25 Mr. Mercedes S1E10
//These two columns are in the Column 1 and 2 of the Worksheet
//Active the Workbook and run the following script

dataset sbc = {1, 2}; //Select the columns for the primary sort and the secondary sort
dataset sodr= {9, 9}; //Select the sort orders: col(1)--ascending and numeric suffix combination , col(2)--ascending and numeric suffix combination 
wsort nestcols:=sbc order:=sodr;

Keywords:nested sort