cancel
Showing results for 
Search instead for 
Did you mean: 

Null Value for a Type

vikas_agarwal
New Contributor
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:`b`g`x`h`i`j`e`f`c`s`p`m`d`z`n`u`v`t!(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`$x`t} each metaCol (startCol-1)+til cnt-startCol-1
}


/ some existing table 
;tbl:([]a:1 2 3 4 5;b:`a`b`c`d`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.
4 REPLIES 4

charlie
New Contributor II
New Contributor II
to get a null type of a vector

q)first 0#010101b
0b

q)first each value flip 0#tbl
0N
`
" "

Thanks Charles!

a_1
New Contributor


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
`
" " 

charlie
New Contributor II
New Contributor II
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).