2.2.3.68 wsort


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.

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

Sort Orders order

Input

vector

<optional>

sorting order index, 1 ascending, 0 descending. Its size should match the one of Nested Sort Columns.

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

  • Code Sample
/*
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

Keywords:nested sort