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
 Origin Forum
 sorting into a new column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

schneide

Germany
45 Posts

Posted - 11/08/2017 :  08:35:26 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Pro 2017
b9.4.0.220
Win7


I would like to sort col A and B on Col A
with the results in col C and D, i.e while retaining the original unsorted data in Col a and B.
How can I do this?

Giselher

Hideo Fujii

USA
1582 Posts

Posted - 11/08/2017 :  11:14:02 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Giselher,

You can enter the following dataset formula in F(X) row header of column C:
sort(A)
One handy trick is to use the following variation of the formula:
sort(wcol(j-2))
Here, "wcol" is the column indicated by the formula with variables, and "j" is a variable to indicate the current
column position. So, this formula is always applicable at any column position to refer to the 2nd column left
of the current(=j) column.

This works for you?

--Hideo Fujii
OriginLab
Go to Top of Page

nick_n

Finland
125 Posts

Posted - 11/08/2017 :  12:54:46 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The same result as Hideo's way will give following:
Copy your original data to C and D columns, select C and D -> right click -> Sort columns -> Ascending (Descending)BR,

Nikolay
Go to Top of Page

schneide

Germany
45 Posts

Posted - 11/09/2017 :  08:46:15 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Unfortunately both methods don't work for me.

Hideos suggestion operates only on one column, but I want to sort the value PAIRS from A and B according to the column A .

nick's suggestion comes closer but needs manual copying which I would like to avoid. When Columns C and D are the results of an automated copying process, a different operation on these columns(such as sorting) is blocked, as I understand.

I want to create a template that automatically updates. Columns A and B are the results of a calculation between other columns.

so the input is:

A B
3 7
1 8
2 9

and the output should be as follows -->

A B C D
3 7 1 8
1 8 2 9
2 9 3 7


Giselher
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 11/09/2017 :  2:10:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Giselher,

Please try the following script.
//////////////////////////////////////////////
sortkeycol=1;       //column# to be sorted
int ncol=wks.ncols; //# of cols
colcopy irng:=[%H]!(1,$(ncol)) orng:=[%H]!wcol(ncol+1); //append duplicated cols
wsort w:=<active> irng:=($(ncol+1):end) bycol:=$(sortkeycol) descending:=0; //sort duplicated cols
//////////////////////////////////////////////
I hope this does your job.

--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 11/09/2017 2:17:54 PM
Go to Top of Page

schneide

Germany
45 Posts

Posted - 11/13/2017 :  03:10:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Nearly there.....

Thanks, this solved the simplified question I put forward but didn't solve my problem entirely.

I would like to use the sheet as a template and copy new data into Columns A and B. This template contains further columns with different data. So the title should better have been "sorting into an existing column"

Above solution adds new columns to the end of the worksheet each time I execute the calculation. However I would like to place the results in exactly the columns C and D (designated as Col("xsort") and Col("ysort")).

I tried using wks.col("xsort").svrm=0; to make the column accessible to sorting after copying, but I didn't manage to make it work.

I could imagine that
1. deleting the old columns C and D
2. using above solution
3. moving the columns to the correct position within the worksheet
might do the job. But isn't there an easier solution?

Giselher

Edited by - schneide on 11/14/2017 03:08:01 AM
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