As the definition of xrank says it is a uniform function and ranks data into uniform group. There are some side effect because of this. Take this example. 2 xrank 3 3 4 4 4 4 4.
Value 4 sometime gets ranked as 0 and sometime gets ranked as 1. is there any way to rank values in a non-uniform way?
-Shailesh
Hi,
xrank is:
k) _y*x%#y:<<y
q) floor y*x%count y:rank y
I think you want something like:
q) floor y*x%count y:(first;rank y) fby y
Which uses the lowest rank of each value. An alternative would be to use the median xrank:
q) (med; x xrank y) fby y
Best,
George
It sounds like you essentially want the rank on the distinct items:
q)urank:{xrank[x;d](d:distinct y)?y}
q)2 xrank 3 3 4 4 4 4 4
0 0 0 0 1 1 1
q)urank[2;3 3 4 4 4 4 4]
0 0 1 1 1 1 1
You might want to test it to make sure this ranking even makes sense as the buckets could be a lot less evenly distributed.
Terry
This should do the trick. Thank you so much Terry. yes will test various scenarios before using it on real data and rolling it out.
-Shailesh
Somewhat similar idea
q)k).q.uxrank:{_y*x%#y:(|/'(<<y)@=y)y}
q)
q)2 uxrank 3 3 4 4 4 4 4
0 0 1 1 1 1 1
PS: Lately I am finding some of the posts don’t appear on the group or get delayed arbitrarily, not sure who is moderating and if its completely manual.