Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an `outer` or `exclusive or` operator equivalent to `inter` in KDB?

Tags:

list

xor

kdb

Let's say I have the following two lists:

 x : `a`b`c`d;
 y : `a`b`e`f;

For the intersection, there is the inter operator:

q)x inter y
`a`b

Is there a similar operator to do the EXCLUSIVE OR such that I would get:

q)x outer y
`c`d`e`f

?

like image 270
JejeBelfort Avatar asked Dec 08 '22 12:12

JejeBelfort


1 Answers

the operation except will give you elements of one list that do not belong in another.

However in your case x except y would only give `c`d and y except x would only give `e`f.

Therefore you could use either;

q)(x except y),y except x
`c`d`e`f

or

q)(x union y) except (x inter y)
`c`d`e`f

or alternatively without using except

q)where(count each group (distinct x), distinct y)=1
`c`d`e`f

if you want to get a list of all exclusive elements.

Regards, Kevin

like image 97
Kevin O'Hare Avatar answered Dec 31 '22 15:12

Kevin O'Hare