Also easy extendible to more columns, e.g. sorting ascending on first 2 columns
and descending on last ones.
[x=.|:'abc'{~ 20 4 ?.@$3
accbacabbabcbbbbcbcb
cbbcbabaabcaaacababc
bbabbbacccaababbbbca
abcccbcacacbaacabacc
/:~(2&{."1 <@(\:_2&{."1)/.])|: x
+----+----+----+----+----+----+
|abca|acba|bacc|bcbc|cabb|cbcc|
|abbc| |baca|bcbc|caab|cbbb|
|abac| |baba|bcac| |cbbb|
| | |baba|bcac| |cbac|
| | |baba| | | |
| | |baaa| | | |
+----+----+----+----+----+----+
Ravelling finishes the job.
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: Programming <[email protected]>
> Namens R.E. Boss
> Verzonden: zondag 20 januari 2019 12:14
> Aan: [email protected]
> Onderwerp: Re: [Jprogramming] Sorting on two keys
>
> [x=.'abcdefg'{~ 10 2?.@$8<mailto:2?.@$8>
> ;/:~({."1 <@(\:{:"1)/.]) x
> be
> bb
> ba
> ce
> ce
> db
> ed
> ec
> fe
> fa
>
>
> R.E. Boss
>
> > -----Oorspronkelijk bericht-----
> > Van: Programming
> > <[email protected]<mailto:[email protected]>>
> > Namens 'Bo Jacoby' via Programming
> > Verzonden: zaterdag 19 januari 2019 19:13
> > Aan: 'Pascal Jasmin' via Programming
> > <[email protected]<mailto:[email protected]>>
> > Onderwerp: Re: [Jprogramming] Sorting on two keys
> >
> >
> > t{~/:(10*9-0{"1 t)+1{"1 t
> >
> > 8 2
> >
> > 8 3
> >
> > 8 4
> >
> > 7 2
> >
> > 7 4
> >
> >
> >
> >
> >
> > Den lørdag den 19. januar 2019 17.51.43 CET skrev 'Pascal Jasmin'
> > via Programming
> > <[email protected]<mailto:[email protected]>>:
> >
> > if one of the columns is numeric, then negating it will sort the right way.
> >
> > (\: 1 ,/@(+`-\"1) ]) 5 2$7 4 8 2 8 4 7 2 8 3
> >
> >
> >
> >
> > ________________________________
> > From: Jimmy Gauvin <[email protected]<mailto:[email protected]>>
> > To: [email protected]<mailto:[email protected]>
> > Sent: Saturday, January 19, 2019 11:18 AM
> > Subject: [Jprogramming] Sorting on two keys
> >
> >
> >
> > Hi,
> >
> >
> > I need to sort on two keys, one descending the other asscending.
> >
> > (J takes care were ascending or descending
> >
> >
> > Is there a better way to solve this ?
> >
> >
> > ]t=:5 2$7 4 8 2 8 4 7 2 8 3
> >
> > 7 4
> >
> > 8 2
> >
> > 8 4
> >
> > 7 2
> >
> > 8 3
> >
> > ]tt=: t {~ /:1{"1 t
> >
> > 8 2
> >
> > 7 2
> >
> > 8 3
> >
> > 7 4
> >
> > 8 4
> >
> > ]tt {~ \:0{"1 tt
> >
> > 8 2
> >
> > 8 3
> >
> > 8 4
> >
> > 7 2
> >
> > 7 4
> >
> >
> > Thanks,
> >
> >
> > Jimmy
> >
> > ----------------------------------------------------------------------
> >
> > For information about J forums see
> http://www.jsoftware.com/forums.htm
> > ----------------------------------------------------------------------
> > For information about J forums see
> http://www.jsoftware.com/forums.htm
> > ----------------------------------------------------------------------
> > For information about J forums see
> http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm