[Jprogramming] Sorting on two keys
R.E. Boss
r.e.boss at outlook.com
Wed Jan 23 10:45:10 UTC 2019
If your x variable denotes the columns to be sorted plus the way in which that should be done, like
0 3 2 1,:_1 1 _1 1
Then the (explicit) toolbox verb could be
foo=:4 : ('''x1 x2''=.x' ; 'x2([/: *"1)&.:(x1&C."1)~ y')
a ,.@;~&|: (0 3 2 1,:_1 1 _1 1) foo a=.3#.^:_1 i.30
+-----------------------------------------------------------+
|1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0|
|0 0 0 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2|
|0 0 0 2 2 2 1 1 1 0 0 0 2 2 2 1 1 1 0 0 0 2 2 2 1 1 1 0 0 0|
|0 1 2 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2|
+-----------------------------------------------------------+
|0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1|
|0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 0 0 0|
|0 0 0 1 1 1 2 2 2 0 0 0 1 1 1 2 2 2 0 0 0 1 1 1 2 2 2 0 0 0|
|0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2|
+-----------------------------------------------------------+
R.E. Boss
> -----Oorspronkelijk bericht-----
> Van: Programming <programming-bounces at forums.jsoftware.com>
> Namens Jimmy Gauvin
> Verzonden: dinsdag 22 januari 2019 00:34
> Aan: programming at jsoftware.com
> Onderwerp: Re: [Jprogramming] Sorting on two keys
>
> HI,
>
> thanks for all the answers, and the insights into J and sorting.
> The version applicable to my sorting needs is indeed the classic primary key,
> secondary key sort.
> And the R.E. Boss version is going into my toolbox.
>
>
> Jimmy
>
More information about the Programming
mailing list