> > On Sat, Jan 19, 2019 at 8:40 AM Roger Hui <rogerhui.can...@gmail.com> > wrote: > > > If the keys are numeric you can multiply the ascending column by 1 and > > the descending one by _1, and then apply /: . > >
It is not enough to multiply with 1 or _1 for ascending or descending columns. You might have to reorder the columns as well. Suppose the 3-column matrix x with |:x=. ,/^:2 >{3#<i.3 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 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 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 has to be sorted ascending by column 0, descending by column 2 and ascending by column 1, in that order. Multiplying columns by 1 1 _1 and sorting would deliver |:1 1 _1( ]/: *"1 ) x 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 1 1 1 2 2 2 0 0 0 1 1 1 2 2 2 0 0 0 1 1 1 2 2 2 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 2 1 0 Whereas this is (the transposed of) what we want |: 1 1 _1( ]/: *"1)&.:(0 2 1&C."1) x 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 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 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 R.E. Boss ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm