Search code examples
kdbq-lang

Create a Boolean column displaying comparison between 2 other columns in kdb+


I'm currently learning kdb+/q. I have a table of data. I want to take 2 columns of data (just numbers), compare them and create a new Boolean column that will display whether the value in column 1 is greater than or equal to the value in column 2.

I am comfortable using the update command to create a new column, but I don't know how to ensure that it is Boolean, how to compare the values and a method to display the "greater-than-or-equal-to-ness" - is it possible to do a simple Y/N output for that?

Thanks.


Solution

  • / dummy data
    q) show t:([] a:1 2 3; b: 0 2 4)
        a b
        ---
        1 0
        2 2
        3 4
    
    / add column name 'ge' with value from b>=a
    q) update ge:b>=a from t
        a b ge
        ------
        1 0 0
        2 2 1
        3 4 1