Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

- JMP User Community
- :
- Discussions
- :
- Ranking Tie with multiple duplicates

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Created:
Dec 14, 2018 12:14 PM
| Last Modified: Dec 16, 2018 8:30 PM
(3003 views)

All,

This is a follow up question to https://community.jmp.com/t5/Discussions/Sort-a-matrix/m-p/85678#M38246 .

```
sort_matrix = Function( {m, order = "ascending"}, {t, b = [], i = [], default local},
If( order == "ascending" | order == "Ascending",
For( r = 1, r <= N Cols( m ), r++,
t = m[0, r];
b ||= Sort Ascending( t );
i ||= Matrix( As List( Rank Index( t ) ) );
);
Eval List( {b, i} );
,
// else
If( order == "descending" | order == "Descending",
For( r = 1, r <= N Cols( m ), r++,
t = m[0, r];
b ||= Sort Descending( t );
i ||= Matrix( Reverse( As List( Rank Index( t ) ) ) );
);
Eval List( {b, i} );
)
);
);
```

So, the current implementation of this function arbitrarily resolves ties. What I would like to do is deal with ties by preserving the order of the elements. For e.g.

```
A = [1 0 1];
{b,i} = sort_matrix(A);
b=
0 1 1
i=
2 1 3
```

I was hoping that using the Ranking Tie() in place of Rank Index above and then reassigning the positions would help resolve it for me. However, in the case of more than 2 ties, the Ranking Tie() opens up another issue i.e., it provides a different result depending on whether the input has an even number of suplicates or odd number of duplicates . Any thoughts ?

Best

Uday

Uday

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Created:
Dec 16, 2018 8:31 PM
| Last Modified: Dec 17, 2018 11:10 AM
(2959 views)
| Posted in reply to message from uday_guntupalli 12-14-2018

@adammorris,

Thank you for offering the solution. Adam helped me via the JMP Technical Support platform and here is the answer for anyone who is curious .

```
Clear Log(); Clear Globals();
/*A = [10 -12 4 8; 6 -9 8 0; 2 3 11 -2; 1 1 9 3];*/
sort matrix = Function( { m,order }, { t, b=[], i=[] },
If(order == "ascending",
For( r = 1, r <= N Cols( m ), r++,
t = A[0,r];
b ||= Sort Ascending( t );
i ||= Matrix( As List( Rank Index( t ) ) );
);
Eval List( { b, i } );
,
// else
If(order == "descending",
For( r = 1, r <= N Cols( m ), r++,
t = A[0,r];
b ||= Sort Descending( t );
i ||= Matrix(As List( Rank Index( -t ) )) ;
);
Eval List( { b, i } );
);
);
);
```

Best

Uday

Uday

1 REPLY 1

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Created:
Dec 16, 2018 8:31 PM
| Last Modified: Dec 17, 2018 11:10 AM
(2960 views)
| Posted in reply to message from uday_guntupalli 12-14-2018

@adammorris,

Thank you for offering the solution. Adam helped me via the JMP Technical Support platform and here is the answer for anyone who is curious .

```
Clear Log(); Clear Globals();
/*A = [10 -12 4 8; 6 -9 8 0; 2 3 11 -2; 1 1 9 3];*/
sort matrix = Function( { m,order }, { t, b=[], i=[] },
If(order == "ascending",
For( r = 1, r <= N Cols( m ), r++,
t = A[0,r];
b ||= Sort Ascending( t );
i ||= Matrix( As List( Rank Index( t ) ) );
);
Eval List( { b, i } );
,
// else
If(order == "descending",
For( r = 1, r <= N Cols( m ), r++,
t = A[0,r];
b ||= Sort Descending( t );
i ||= Matrix(As List( Rank Index( -t ) )) ;
);
Eval List( { b, i } );
);
);
);
```

Best

Uday

Uday

Article Labels

There are no labels assigned to this post.