What does error output ‘nyi mean?

‘nyi means, “not yet implemented.” Sometimes you see this error for expressions that are simply wrong. In any case, you need to try a different approach.

See also: kdb error code table

How do I sort?

Short answer: asc and desc:

q)asc 3 5 2 0 1
`s#0 1 2 3 5
q)desc 3 5 2 0 1
5 3 2 1 0

Notice that, in the case of asc, q attaches the `s attribute to the result. (There is no corresponding attribute for a descending sort.)

As an aside, you may be surprised to discover that calling asc on an attribute-free list that happens to be in sorted order will have the `s attribute applied to it as a side effect:

q)list: til 1000
q)attr list
q)asc list
`s#0 1 2 3 4 5 6 7 8 9 10 ..
`s#0 1 2 3 4 5 6 7 8 9 10 ..

Also take a look at iasc and idesc.

Finally, to sort a table instead of a list, see xasc and xdesc. Read more about sorting tables from this faq

This work is licensed under a Creative Commons License.
The views and opinions expressed herein are those of the authors and do not necessarily reflect those of any other person or legal entity.
Kdb+ is the registered trademark of Kx Systems, Inc.