The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Sorting multiple columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Mats77sv

Sweden
10 Posts

Posted - 09/26/2014 :  08:21:50 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 9pro
Operating System:win7

Hi,

I have a problem sorting 11 columns (col(24) to col(34)) with respect to the first column, col(24).
For instance, if I after sorting look at all rows with a values of 5 in col(24), the order of which the rows appears seen more or less random. I can see that because I have "time" in one of the other sorted columns, col(33). I have used:

wsort bycol:=24 c1:=24 c2:=34 missing:=1;

Is there anyone who knows what is wrong?

greg

USA
1378 Posts

Posted - 09/26/2014 :  09:03:44 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Your command should reorder rows in columns 25 to 34 by sorting column 24. The only column which would be in sorted order is column 24.

If you want each of those columns sorted individually, then you would need a loop:

loop(jj,24,34)
{
wsort bycol:=jj c1:=jj c2:=jj missing:=1;
}
Go to Top of Page

Mats77sv

Sweden
10 Posts

Posted - 09/28/2014 :  4:13:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It is not exactly what I want so I will try to explain it again.

I want to sort all the rows from col(24) to col(34) with respect to col(24). Example: After sorting, I have ex. 3 rows (ex. row no. 6, 12, and 51) with similar values in col(24) ex. 5. These 3 rows should be arranged in the same order of appearing (6, 12, and 51) - right after each other. However, as it is now, they appear in the order 12, 51, and 6. Hope it makes more sense now.

If I use the loop-command you suggest I will sort column by column and split up the rows.
Go to Top of Page

greg

USA
1378 Posts

Posted - 09/29/2014 :  09:21:25 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
When you sort on only one column, there is no guarantee that order will be preserved in the sort group when all values are the same. Sorting would actually be slowed down by such a requirement.

To do that you would need a secondary sort group, but since none of your other columnns would guarantee no order change then you need to create a column that does. A column filled with row numbers should do the trick:

// BEGIN SCRIPT
wks.col = 25; // Locate insertion point
wks.insert(TEMPSORT); // Insert a temporary column
get col(24) -e last; // Find how much data to sort
col(TEMPSORT) = data(1,last); // Fill temp column with row values
dataset sbc = {24, 25}; // Select the columns for the primary sort and the secondary sort
dataset sodr= {1, 1}; // Select the sort order: col(24)--ascending, col(25)--ascending
wsort nestcols:=sbc order:=sodr c1:=24 c2:=35 missing:=1; //Perform the nested sorting
del col(TEMPSORT);
// END SCRIPT
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000