Null Value for a Type

Hi,

I was required in my scripts to insert null values for some column but because of number of columns were large, i thought to write a function that will give me such values. But somehow i was not able to find a direct way to find that null values for columns of table.

Temporarily i wrote following, not sure if it is correct:

;NullValDictionary:bgxhijefcspmdznuvt!(0b;0Ng;0x00;0Nh;0N;0Nj;0Ne;0n;" ";`;0Np;0Nm;0Nd;0Nz;0Nn;0Nu;0Nv;0Nt)

;AddNullValueBaseOnCol:{[tbll;startCol]

;metaCol:0!meta tbll

;cnt:count metaCol

; {NullValDictionary$xt} each metaCol (startCol-1)+til cnt-startCol-1

}

/ some existing table 

;tbl:(a:1 2 3 4 5;b:abcd`e;c:“abcde”)

/ following return an array of the null values from the column number 2

;AddNullValueBaseOnCol[tbl;2]

Please let me know if any better/right way.

to get a null type of a vector

q)first 0#010101b

0b

q)first each value flip 0#tbl

0N

`

" "

Thanks Charles!

On Friday, February 27, 2015 at 5:06:36 AM UTC-5, Charles Skelton wrote:

to get a null type of a vector

q)first 0#010101b

0b

I prefer using v[0N], v@0N, or just v 0N to get the null type for a vector v. You can also use -1 instead of 0N, but I find 0N more suggestive.

 

q)first each value flip 0#tbl

0N

`

" "

q)@[;0N]each value flip tbl

0N

`

" " 

Indexing out of domain will return a null.

first 0#x

also works for atoms, so it’s a handy idiom to remember (and is one used by Arthur).