Hi Rory,
You have to make the key of the dictionary into symbol format and also the rank error is due to the value d being all atoms and not list so these must be enlisted.
q)d:{count each group y xbar x}
q)x:1000?100
q)k:d[x;10]
q)k
50| 91
20| 101
30| 119
10| 118
70| 106
40| 99
80| 92
90| 84
60| 108
0 | 82
q)tab:flip(`$(string key k))!enlist each value k
q)tab
50 20 ?30 ?10 ?70 ?40 80 90 60 ?0
91 101 119 118 106 99 92 84 108 82
q)type tab
98h
Hope this helps.
Thanks Rory
Hi Guys,
Perhaps a slightly more terse solution would be;
q)tab:enlist (`$string key k)!value k
q)tab
10? 0?? 90 70? 40? 80 60? 50? 30? 20
104 100 99 101 100 89 100 109 109 89
q)type tab
98h
Kind regards,
Paul
Also if you change the ‘d’ function to:
d:{count each group `$string y xbar x}
you get a even shorter solution:
q)enlist d[x;10]
30 0 50 60 70 90 40 80 20 10
87 97 114 111 83 110 105 103 97 93
Regards,
Petru
Sorry - just as a final coda to this topic - I had neglected to sort the bins, so the function now looks like:
d:{h:count each group y xbar x; (`$(string asc key h))!(enlist each h[asc key h])}
Can anyone make this more compact / elegant? My approach looks a bit clunky to my eyes..
Hi,
This should do it.
q)x:1000?100
q)d:{h:count’[group y xbar x];(`$string a)!h a:asc key h}
q)enlist d[x;10]
0? 10 20 30 40? 50 60? 70? 80? 90
99 96 95 98 101 98 100 102 115 96
Regards,
Paul