Search code examples
kdb

kdb apply function in select by row


I have a table

t: flip `S`V ! ((`$"|A|B|"; `$"|B|C|D|"; `$"|B|"); 1 2 3)

and some dicts

t1: 4 10 15 20 ! 1 2 3 5;
t2: 4 10 15 20 ! 0.5 2 4 5;

Now I need to add a column with values on the the substrings in S and the function below (which is a bit pseudocode because I am stuck here).

f:{[s;v];
    if[`A in "|" vs string s; t:t1;];
    else if[`B in "|" vs string s; t:t2;];
    k: asc key t;
    :t k k binr v;
}

problems are that s and v are passed in as full column vectors when I do something like

update l:f[S,V] from t;

How can I make this an operation that works by row? How can I make this a vectorized function? Thanks


Solution

  • You will want to use the each-both adverb to apply a function over two columns by row.

    In your case:

    update l:f'[S;V] from t;