2022.06.30 07:59 AM
Hi,
Is there a way to link vector columns so that when we do something like asc, the corresponding column will also re-arrage:
tbl:([] sVec:((`b`c`a);(`c`a`b);(`a`b`c));sNum:((2 3 1);(3 1 2);(1 2 3)));
tbl
sVec sNum
-----------
b c a 2 3 1
c a b 3 1 2
a b c 1 2 3
update sVec:asc'[sVec] from tbl
sVec sNum
-----------
a b c 2 3 1
a b c 3 1 2
a b c 1 2 3
Desired output (Where each symbol is linked to number in same vector position):
tbl1
sVec sNum
-----------
a b c 1 2 3
a b c 1 2 3
a b c 1 2 3
Many thanks!
2022.06.30 08:09 AM
iasc gives you the sorted idexes which you can use
q)update sVec:sVec(@)'iasc each sNum,asc each sNum from tbl
sVec sNum
-----------
a b c 1 2 3
a b c 1 2 3
a b c 1 2 3
2022.06.30 08:09 AM
iasc gives you the sorted idexes which you can use
q)update sVec:sVec(@)'iasc each sNum,asc each sNum from tbl
sVec sNum
-----------
a b c 1 2 3
a b c 1 2 3
a b c 1 2 3
2022.06.30 09:03 AM
Nice solution, thank you!
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.