cols, xcol, xcols
Table columns
cols
Column names of a table
cols x cols[x]
Where x is a
- table
- the name of a table as a symbol atom
- a filesymbol for a splayed table
returns its column names as a symbol vector.
q)\l trade.q
q)cols trade /value
`time`sym`price`size
q)cols`trade /reference
`time`sym`price`size
xcol
Rename table columns
x xcol y xcol[x;y]
Where y is a table passed by value, and x is
- a symbol vector of length no greater than
count cols yreturnsywith its firstcount xcolumns renamed - a dictionary formed from two symbol vectors, returns
ywith the columns inkey xrenamed asvalue x
q)t:([]a:3 4 5; b:6 7 8; c:`z`u`i)
q)`d`e xcol t / rename first two columns
d e c
-----
3 6 z
4 7 u
5 8 i
q)([a:`A;c:`C]) xcol t / rename selected columns
A b C
-----
3 6 z
4 7 u
5 8 i
q)([q:`r]) xcol t / nonexistent column names in key x signal a length error
'length
[0] ([q:`r]) xcol t
Q for Mortals
§9.8.1 xcol
xcols
Reorder table columns
x xcols y xcols[x;y]
Where
yis a simple table passed by valuexis a symbol vector of some or all ofy’s column names (can also be an atom)
returns y with x as its first column/s.
q)t:([]a:3 4 5; b:6 7 8; c:`z`u`i)
q)`b xcols t
b a c
-----
6 3 z
7 4 u
8 5 i
q)t:xcols[reverse cols t;t] / reverse cols and reassign
q)cols t
`c`b`a
Q for Mortals
§9.8.2 xcols