# ?"row by row processing"

**URL:** https://forum.kx.com/t/row-by-row-processing/6345
**Category:** Community Support
**Tags:** kdb-and-q
**Created:** [November 13, 2009, 6:43pm UTC](https://forum.kx.com/t/row-by-row-processing/6345 "2009-11-13T18:43:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ramdas](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@Ramdas](https://forum.kx.com/u/Ramdas)
#### Post date: [November 13, 2009, 6:43pm UTC](https://forum.kx.com/t/row-by-row-processing/6345/1 "2009-11-13T18:43:00Z")

</div>

Hello,

If I have a table -

## a b c

1 2 3  
6 4 2  
5 5 1

How do I do something like this --

update myval: $[a\<=b;[a];[c]] from

I want result like --

## a b c myval

1 2 3 1  
6 4 2 2  
5 5 1 1

Thanks in Advance,  
Ramdas

---

<div class="post-metadata">

### Author: ![heydi1](https://avatars.discourse-cdn.com/v4/letter/h/f17d59/32.png) [@heydi1](https://forum.kx.com/u/heydi1)
#### Post date: [November 13, 2009, 6:53pm UTC](https://forum.kx.com/t/row-by-row-processing/6345/2 "2009-11-13T18:53:00Z")

</div>

update myval:(c\*a\>=b)+(a\*a\<b) from \<table\>?

2009/11/13 Ramdas \<rthatte@gmail.com\>

> Hello,
> 
> If I have a table -
> 
> ## a ? b ? c
> 
> 1 ? 2 ? 3  
> 6 ? 4 ? 2  
> 5 ? 5 ? 1
> 
> How do I do something like this –
> 
> update myval: $[a\<=b;[a];[c]] from \<table\>
> 
> I want result like –
> 
> ## a ? ?b ? ?c ? ?myval
> 
> 1 ? ?2 ? ?3 ? ?1  
> 6 ? ?4 ? ?2 ? ?2  
> 5 ? ?5 ? ?1 ? ?1
> 
> Thanks in Advance,  
> Ramdas

---

<div class="post-metadata">

### Author: ![charlie1](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@charlie1](https://forum.kx.com/u/charlie1)
#### Post date: [November 13, 2009, 7:22pm UTC](https://forum.kx.com/t/row-by-row-processing/6345/3 "2009-11-13T19:22:00Z")

</div>

vector conditional

?[condition;true;false]

e.g.

update myval: ?[a\<=b;a;c] from \<table\>

---

<div class="post-metadata">

### Author: ![daniel\_brandstr](https://avatars.discourse-cdn.com/v4/letter/d/f14d63/32.png) [@daniel\_brandstr](https://forum.kx.com/u/daniel_brandstr)
#### Post date: [November 14, 2009, 12:27am UTC](https://forum.kx.com/t/row-by-row-processing/6345/4 "2009-11-14T00:27:00Z")

</div>

And if you need to apply a function to each row you can use the each-both adverb '.

## q)table:( a:1 6 5; b:2 4 5; c:3 2 1) q)update myval:{$[x\<y;x;z]}'[a;b;c] from table a b c myval

1 2 3 1  
6 4 2 2  
5 5 1 1

In your case though, I would go with the vector conditional since that is much faster.

q)table:( a:1000?100; b:1000?100; c:1000?100)  
q)\t do[10000;update myval:{$[x\<y;x;z]}'[a;b;c] from table;]  
2561  
q)\t do[10000;update myval:?[a\<b;a;c] from table;]  
114

---

<div class="post-metadata">

### Author: ![Ramdas](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@Ramdas](https://forum.kx.com/u/Ramdas)
#### Post date: [November 16, 2009, 1:34pm UTC](https://forum.kx.com/t/row-by-row-processing/6345/5 "2009-11-16T13:34:00Z")

</div>

Thanks guys,Vector condition worked well.–RamdasOn Nov 13, 6:27?pm, Daniel Br?ndstr?m \<daniel.brandst…\>wrote:\> And if you need to apply a function to each row you can use the each-both\> adverb '.\>\> q)table:( a:1 6 5; b:2 4 5; c:3 2 1)\> q)update myval:{$[x a b c myval\> -----------\> 1 2 3 1\> 6 4 2 2\> 5 5 1 1\>\> In your case though, I would go with the vector conditional since that is\> much faster.\>\> q)table:( a:1000?100; b:1000?100; c:1000?100)\> q)\t do[10000;update myval:{$[x 2561\> q)\t do[10000;update myval:?[a **114\>\>\>\>\>\> On Fri, Nov 13, 2009 at 8:22 PM, Charles Skelton \<char…\> wrote:\> \> vector conditional\>\> \> ?[condition;true;false]\>\> \> e.g.\>\> \> update myval: ?[a\<=b;a;c] from**

**\>\> \> On Fri, Nov 13, 2009 at 7:43 PM, Ramdas \<rtha…\> wrote:\>\> \>\> Hello,\>\> \>\> If I have a table -\>\> \>\> a ? b ? c\> \>\> ------------\> \>\> 1 ? 2 ? 3\> \>\> 6 ? 4 ? 2\> \>\> 5 ? 5 ? 1\>\> \>\> How do I do something like this –\>\> \>\> update myval: $[a\<=b;[a];[c]] from** 

**\>\> \>\> I want result like –\>\> \>\> a ? ?b ? ?c ? ?myval\> \>\> ----------------------------\> \>\> 1 ? ?2 ? ?3 ? ?1\> \>\> 6 ? ?4 ? ?2 ? ?2\> \>\> 5 ? ?5 ? ?1 ? ?1\>\> \>\> Thanks in Advance,\> \>\> Ramdas\>\> –\> Hey! It compiles! Ship it!\> — Hide quoted text -\>\> - Show quoted text -**

**\</rtha…\>**
