mmv456
mmv456

Reputation: 23

kdb/q How to append a list to a table?

I have a table like this:

nameTable

Name Included
Ann 1
Bob 0
Cat 1

I have a function that gets the "bits" from the Included? column:

// get the bits
fGetBits:{[nameTable]
  nameTable: select Included from nameTable;
  //BitsTable
  value flip nameTable}

This returns the following, of type 0h:

1 0 1

My question is how can I then take this 0h list and add it back to the Included column of the nameTable table, replacing the current values?

So for example, if I had the following:

0 1 1

I want my table to now look like this:

Name Included
Ann 0
Bob 1
Cat 1

Thanks for the help.

Upvotes: 0

Views: 193

Answers (2)

terrylynch
terrylynch

Reputation: 13657

Also worth mentioning a simple update statement https://code.kx.com/q/ref/update/

q)update Included:011b from([] Name:`Ann`Bob`Cat;Included:101b)
Name Included
-------------
Ann  0
Bob  1
Cat  1

Upvotes: 2

rianoc
rianoc

Reputation: 3786

The question is a little hard to follow but:

q)nameTable:([] Name:`Ann`Bob`Cat;Included:101b)
q)nameTable
Name Included
-------------
Ann  1
Bob  0
Cat  1
q)exec Included from nameTable
101b
q)type exec Included from nameTable
1h
q)nameTable[`Included]:011b
q)nameTable
Name Included
-------------
Ann  0
Bob  1
Cat  1
q)

Upvotes: 3

Related Questions