Column Update

Question: Define a function updCol that takes in a table as a value or reference, column name, and function to operate on the column that returns an updated column list. If a reference is passed in, the update should be persisted and the reference should be returned, otherwise the updated value is returned.

More Information:

https://code.kx.com/q/ref/amend

Example

                                
                                q)show t:([]s:`AAPL`IBM`MSFT;p:100 200 300)
s    p
--------
AAPL 100
IBM  200
MSFT 300
q)updCol[t;`p;2*]
s    p
--------
AAPL 200
IBM  400
MSFT 600
q)updCol[`t;`p;3*]
`t
q)t
s    p
--------
AAPL 300
IBM  600
MSFT 900
q)`:t/ set .Q.en[`:.] t
`:t/
q)updCol[`:t;`p;4*]
`:t
q)get `:t
s    p
---------
AAPL 1200
IBM  2400
MSFT 3600
                                
                            

Solution

Tags:
tables
Searchable Tags
algorithms api architecture asynchronous c csv data structures dictionaries disk feedhandler finance functions ingestion ipc iterators machine learning math multithreading optimizations realtime shared library sql statistics streaming strings tables temporal utility websockets