q - 按组频率过滤

q - filter by group frequencies

我想根据特定列中组的频率条件过滤 table。示例:

给定 table

tmp:([] id:`a`a`b`b`b`c; c2:1 2 3 4 5 6)

先求出每组的频率

ce:count each group tmp[`id]

然后 select tmpid 的组数超过 1

的行
select from tmp where id in where ce > 1

id  c2
a   1
a   2
b   3
b   4
b   5
(row id=`c is gone because it appeared only once)

如何才能做得更优雅?

谢谢

您可以使用 fby 例如

q)select from tmp where 1<(count;i) fby id
id c2
-----
a  1
a  2
b  3
b  4
b  5