# what is rank in kdb ?

**URL:** <https://forum.kx.com/t/what-is-rank-in-kdb/10372>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [September 13, 2015, 4:27am UTC](https://forum.kx.com/t/what-is-rank-in-kdb/10372 "2015-09-13T04:27:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![User7](https://avatars.discourse-cdn.com/v4/letter/u/7ea924/32.png) [@User7](https://forum.kx.com/u/User7)\
**Post date:** [September 13, 2015, 4:27am UTC](https://forum.kx.com/t/what-is-rank-in-kdb/10372/1 "2015-09-13T04:27:00Z")

</div>

What is the rank in kdb mean ?

[http://code.kx.com/wiki/Reference/QuestionSymbol](http://code.kx.com/wiki/Reference/QuestionSymbol)

However, if the right argument is a general list then items of the left argument are matched with items of the right argument. For example,

```
q)u?(2 3;`ab)3 3

```

In this case Find matches items of the left argument with&nbsp;2 3&nbsp;and&nbsp;`ab</tt>&nbsp;, not&nbsp;<tt style='"font-family:' monospace new>(2 3;`ab).

? is rank sensitive; x?y can’t deal with mixed rank x. If rank x is n then x?y looks for objects of rank n-1. e.g.

```
2 3?2 3#til 6 / looks for rank 0 objects(0 1 2;4 5)?2 3#til 6 / looks for rank 1 objects

```

---

<div class="post-metadata">

**Author:** ![LamHinYan](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@LamHinYan](https://forum.kx.com/u/LamHinYan)\
**Post date:** [September 13, 2015, 12:22pm UTC](https://forum.kx.com/t/what-is-rank-in-kdb/10372/2 "2015-09-13T12:22:00Z")

</div>

[www.jsoftware.com/papers/j4apl1.htm#items](http://www.jsoftware.com/papers/j4apl1.htm#items)

---

<div class="post-metadata">

**Author:** ![ag12](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@ag12](https://forum.kx.com/u/ag12)\
**Post date:** [March 9, 2018, 7:36am UTC](https://forum.kx.com/t/what-is-rank-in-kdb/10372/3 "2018-03-09T07:36:00Z")

</div>

q)3 4#til 12

0 1 2 3

4 5 6 7

8 9 10 11

q)count [3 4#til 12]

3

Is there an APL ? (Rho) equivalent for q? 3 4

---

<div class="post-metadata">

**Author:** ![effbiae](https://avatars.discourse-cdn.com/v4/letter/e/ecae2f/32.png) [@effbiae](https://forum.kx.com/u/effbiae)\
**Post date:** [March 9, 2018, 8:41am UTC](https://forum.kx.com/t/what-is-rank-in-kdb/10372/4 "2018-03-09T08:41:00Z")

</div>

there’s no rho primitive in q.&nbsp; q is distinct from j in that it allows ragged arrays

nothing preventing a rho lambda being defined.

---

<div class="post-metadata">

**Author:** ![newstudent20171](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@newstudent20171](https://forum.kx.com/u/newstudent20171)\
**Post date:** [March 9, 2018, 8:45am UTC](https://forum.kx.com/t/what-is-rank-in-kdb/10372/5 "2018-03-09T08:45:00Z")

</div>

\>&nbsp; ^ (0 1 2 3;4 5 6 7;8 9 10 11)

3 4

Used to work in k3

count each (0 1 2 3;4 5 6 7;8 9 10 11)

/4

count count&nbsp; each (0 1 2 3;4 5 6 7;8 9 10 11)

3

---

<div class="post-metadata">

**Author:** ![effbiae](https://avatars.discourse-cdn.com/v4/letter/e/ecae2f/32.png) [@effbiae](https://forum.kx.com/u/effbiae)\
**Post date:** [March 9, 2018, 10:06am UTC](https://forum.kx.com/t/what-is-rank-in-kdb/10372/6 "2018-03-09T10:06:00Z")

</div>

a naive implementation of shape:

q)rho:{$[not 0\>type x;count,.z.s first x;()]}

q)rho 3 2 1#1

3 2 1
