English 中文(简体)
如何发现两个清单之间的区别,包括重复内容
原标题:How to find the difference between two lists including duplicate elements
  • 时间:2023-12-18 01:48:51
  •  标签:
  • kdb

Please help me to write a function to find difference of two lists including duplicate elements. Lists are not equal lengths.

q)l1:1 1 2 3 3 4 4 5 6 7
q)l2: 1 1 2 4 5 6
q)l1 except l2
3 3 7      /4 is missing in result
/expected result : 3 3 4 7
问题回答

你们可以尝试这样的事情:

q){$[any found:x in y;x _:first where found;x]}/[l1;l2]
3 3 4 7

它通过第2号中的物品,看看是否有1英里的物品,并放下。

<代码>组功能可在此查阅。

{
  e: (count each group x) - (count each group y); 
  e: (where e>0)#e;
  raze (value e)# (key e)
}

On the 1st step we check how many numbers are in both lists and subtract counts. Then we keep only numbers with positive counts and convert number->count dictionary into desired list.





相关问题
Concat string with number in kdb+ q

I can append a string with number. temp:30 text:"Current temperature is ",string temp show text type text Result "Current temperature is 30" 10h However, if I append one more ...

How do I save a program in kdb/q?

Most of the examples seem to be run in REPL mode. Is it possible to load myprog.q from disk?

Q (kdb): nested where query

What are the ways to in Q to use the results of a nested query in a where clause? I m looking for something similar to SQL statement. select from food where type_id in ( select type_id from ...

Passing db path to l or .Q.l using a variable

I m writing a q script that loads a db in a particular path and does some processing on it. The location of the db is currently hardcoded in the script, but I want to pass the db path as an argument ...

How to convert tic data to 5 minute OHLC?

I am learning KDB+ and have loaded the tic data into the table W as below. My question is, how to transfer the data into 5 (or n) minutes OHLCVA? "Stk_ID","Date","Time","Price","Chg","Vol","Amt","Ty" ...

KDB Find first date with data in each table of a process

I am trying to find first date where we have data available per process over IPC. I tried below but it isn t efficient. Is there a better way to find this? select min date from ({select date from x ...

热门标签