cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

7-Bedrock

## group items and sort table

Hi to all.
I have tables with many elements which I must group according to type and sort them in ascending order based on column 2 of the table in the example file. I have tried to generate a small code but I do not get the desired result.

I hope you can help me.
I attach the file in mathcad Prime with an example of what I want to get.

In advance thank you very much for the help.

1 ACCEPTED SOLUTION

Accepted Solutions
23-Emerald III
(To:BPP)

Here's a function that will do the job:

The first parameter is the matrix you want to sort, the second parameter is the list of columns you successively want to sort on.

Example. Create a matrix with random numbers:

Sort it on columns 1, 3 and then 7:

Or sort it on column7, then 1, then 3:

Note that the function will work with matrix elements being strings or scalars only.

The same function in Prime (but with ORIGIN=0):

Prime 4 file attached.

Success!
Luc

5 REPLIES 5
23-Emerald III
(To:BPP)

You have set ORIGIN=1, so matrix indexes start at 1 (not the default 0). I suppose your 'column 2' of the table is the one labelled 'Col 1' , so its index is 2.

Have you tried

csort(Table1,2)

To sort the entire table on the second column?

I see that you want the table sorted on column 1, and next on column 2.

Now the problem is that while csort does a good job of sorting on one column, if you subsequently sort the resulting sorted table on another column, the first sorting is lost.

The quickest solution to do the sorting of the table you want, is to do it in Excel.

Success!
Luc

20-Turquoise
(To:BPP)

Hi,

Can be done with following steps.

23-Emerald I
(To:BPP)

Just an observation:

EXCEL (in the embedded table) could do this sorting by tipe, then by column 1, in one single operation.  No code required.

23-Emerald III
(To:BPP)

Here's a function that will do the job:

The first parameter is the matrix you want to sort, the second parameter is the list of columns you successively want to sort on.

Example. Create a matrix with random numbers:

Sort it on columns 1, 3 and then 7:

Or sort it on column7, then 1, then 3:

Note that the function will work with matrix elements being strings or scalars only.

The same function in Prime (but with ORIGIN=0):

Prime 4 file attached.

Success!
Luc

7-Bedrock
(To:LucMeekes)

Thanks to all for the help

Announcements