~. and #/.~ maintain the order of their argument.

So this is one approach:

   hist=: ~. ,: #/.~
   n=:?100#20

   hist/:~ n
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
2 6 2 4 4 7 3 9 3 6  7  4  1  4  8  3  9  3 10  5

You can also sort the result, of course:

   /:~&.|: hist n
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
2 6 2 4 4 7 3 9 3 6  7  4  1  4  8  3  9  3 10  5

I hope this helps,

-- 
Raul

On Tue, Oct 19, 2021 at 4:32 AM Skip Cave <[email protected]> wrote:
>
> How can I modify the standard implicit histogram verb to produce sequential
> categories?
>
> hist =:~.,:#/.~
>
> ]n=.?100#20
>
> 9 12 3 14 3 13 18 8 12 17 17 14 19 9 18 18 16 12 2 4 4 5 13 16 14 11 9 17 8
> 4 14 19 2 9 3 9 7 6 15 14 1 13 14 13 13 19 13 1 4 16 11 12 19 4 2 1 3 18 10
> 15 6 5 10 14 9 3 8 19 14 5 13 8 1 19 2 10 13 3 2 17 18 12 11 9 16 19 11 18
> 14 5 19 3 10 1 5 5 15 7 16 7
>
>
> {"0 hist n
>
> ┌─┬─┬──┬──┬──┬─┬─┬──┬──┬─┬─┬──┬─┬─┬──┬─┬─┬──┬──┬──┐
>
> │3│7│16│10│19│5│9│18│17│4│0│13│6│2│11│8│1│14│15│12│
>
> ├─┼─┼──┼──┼──┼─┼─┼──┼──┼─┼─┼──┼─┼─┼──┼─┼─┼──┼──┼──┤
>
> │3│7│9 │8 │4 │5│6│11│4 │4│2│5 │3│2│3 │4│7│9 │2 │2 │
>
> └─┴─┴──┴──┴──┴─┴─┴──┴──┴─┴─┴──┴─┴─┴──┴─┴─┴──┴──┴──┘
>
>
> What I want:
>
> {"0 m{~"1 /:{. m=.hist n
>
> ┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐
>
> │0│1│2│3│4│5│6│7│8│9│10│11│12│13│14│15│16│17│18│19│
>
> ├─┼─┼─┼─┼─┼─┼─┼─┼─┼─┼──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤
>
> │2│7│2│3│4│5│3│7│4│6│8 │3 │2 │5 │9 │2 │9 │4 │11│4 │
>
> └─┴─┴─┴─┴─┴─┴─┴─┴─┴─┴──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘
>
>
> How can I do all that within the implicit code of hist?
>
>
> Skip Cave
> Cave Consulting LLC
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to