Search code examples
kdb

fills on zeros in KDB


Suppose i have

a: 0 0 1 0 0 2 0 0 0

and I would like to forward fill the zeros to get

filled: 0 0 1 1 1 2 2 2 2

I tried using amend at @[]

a: @[a;where a=0;0N]; 
fills a

but i get the error:

'type
  [0]  a: @[a;where a=0;0N]

I've also tried replacing 0N with null and :: in the amend at statement but none of these approaches work. What do I do?


Solution

  • The issue is that you need to amend a as follows:

    a:@[a;where a=0;:;0N]
    

    Then you can get your expected output with:

    0^fills a