title: [KDB+/Q]: Nested vector conditional
body: <p>How to efficiently and concisely switch formulas dependent on the value of other vector?</p>
  
  <p>According to <a href="http://code.kx.com/q/ref/lists/#vector-conditional" rel="nofollow noreferrer">kx documentation</a>, it is possible to</p>
  
  <blockquote>
    <p>have more than just a true/false selection, e.g. match1/match2/match3/others mapping to result1/result2/result3/default</p>
  </blockquote>
  
  <p>Data:</p>
  
  <pre><code>q)t:([]a:til 5;b:10+til 5;c:100+til 5;d:1000+til 5;g:`I`B`I`U`B) 
  a b  c   d    g
  ---------------
  0 10 100 1000 I
  1 11 101 1001 B
  2 12 102 1002 I
  3 13 103 1003 U
  4 14 104 1004 B
  </code></pre>
  
  <p>I've done it like this:</p>
  
  <pre><code>q)update r:(flip (a+b;c+d;a-d))@'`I`B`U?g from t
  a b  c   d    g r    
  ---------------------
  0 10 100 1000 I 10   
  1 11 101 1001 B 1102 
  2 12 102 1002 I 14   
  3 13 103 1003 U -1000
  4 14 104 1004 B 1108 
  </code></pre>
  
  <p>Question - is there more efficient way (time,space,lines of code)?</p>