Say I'm grouping a data.table by a certain column and counting the values per group. Then I want to remove the groups that have count N < 2
. Is there an efficient, data.table way to do this?
Example data:
id | col1
-------------
1 | "A"
2 | "A"
3 | "B"
4 | "C"
5 | "C"
now: group by col1
and count, remove rows that belong to group with count < 2
Example output: (row 3
was removed)
id | col1
-------------
1 | "A"
2 | "A"
4 | "C"
5 | "C"
I found Subset by group with data.table which is sort of similar, but I don't want to find a specific row per group, but rather identify entire groups if their aggregate satisfies a certain condition.
Thanks