Kdb apply function in row select

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 the substring values ​​in S and the function below (which is pseudo code 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;
}

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

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

How can I do this operation that works on a line? How can I make this a vector function? Thanks

+6
source share
2 answers

You must use each-both adverb to apply the function two columns per row.

In your case:

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

, $, if-else,

f:{[s;v]
  t:$["A"in ls:"|"vs string s;t1;"B"in ls;t2;()!()];
  k:asc key t;
  :t k k binr v;
 };

else , $ , , .

, S V . vs , , string - , .

, !

+2

All Articles