Search code examples
kdb

Extracting kdb list values based on some condition


Say we have a kdb list

L1:(1 2 3 4 5)

Apply condition

L1 < 3

And how can I retrieve result in another list (1 2)


Solution

  • You can use the where keyword for this:

    q)l1 where l1<3
    1 2
    

    Applying l1<3 will return a list of booleans 11000b. Using where on this list will return the index of every 1b

    q)where 11000b
    0 1
    

    Then indexing back into the original list will return the result in another list.