Join Tables Side by Side¶
Source: adopted from here
Introduction¶
In our data analysis, it is quite common to join two kdb tables side by side. Kdb/q provides multiple functions to join two tables. These functions provides different flavors of joining to meet various needs. See more details in Joins.
Question¶
Given two tables with the same number of rows, join them side by side. For example,
t1:([] c1:10?0D;c2:10?til 1000);
t2:([] c3:rand each 10#3.14f;c4:10?`3);
Joining them side by side gives:
c1 c2 c3 c4
---------------------------------------
0D23:01:17.352842688 158 1.149706 mpo
0D00:24:01.519761085 382 2.204227 ghh
0D02:30:54.237189888 770 2.28275 lfh
0D16:46:37.401892393 655 1.50694 dna
0D16:59:18.329750597 156 3.100881 meg
0D12:43:13.668088316 401 1.253591 ifk
0D11:43:06.399342119 11 2.280672 eag
0D00:06:21.593725830 183 1.534317 idf
0D07:13:23.823950886 819 2.052295 acj
0D08:29:24.138744771 849 0.08825518 oji
Answer¶
Two approaches are suggested:
Method 1: Use the fill operator (^
). The typical use case is to replace nulls with non-null values. It can also join tables side by side.
t1^t2
Method 2: Use join operator (,
). It can join atoms, lists, dictionaries and tables. When used together with each ('
), it can join tables column-wise.
t1,'t2