- Aggregated Pivot Table
- Bit Shifting
- Bitwise XOR
- Calculate Tick Size
- Collapsing Dictionaries
- Graphs - Breadth First Search
- Graphs - Depth First Search
- Graphs - Detecting Cycles
- Greatest Common Divisor
- Identity Matrix
- Least Common Multiple
- Log Parser
- Nanosleep
- One Hot Encoding
- Parent Child ID Mapping
- Slippage
- Split Training and Testing Sets
- Stratified Sampling
- Symbol Column Update
- Table Indexing
- Word Count
Reorder Elements
Question: The function 'xcols' reorders the columns of a table by reordering the column list and selecting those columns. Define a function 'reorder' that takes in an atom/list 'x' and a list 'y', and reorders 'y' by 'x'.
Example
q)reorder[`s;`a`b`s]
`s`a`b
q)reorder[`s`b;`a`b`s]
`s`b`a
q)reorder[`f`b;`a`b`s]
`b`a`s
Solution
######## solution.q ########
reorder:{(x where x in y),y where not y in x:(),x}
Explanation: Select the elements of 'y' that are not contained in 'x', and append them to element(s) of 'x' that are contained in y. The element(s) to reorder by are now placed in the front, followed by the other elements of the list 'y'. This function can be leveraged for reordering splayed table columns on disk, where the order of the list contained in the .d file needs to be changed.