Given a vector:
eg.:
a = c(1, 2, 2, 4, 5, 3, 5, 3, 2, 1, 5, 3)
Using a[a%in%a[duplicated(a)]]
I can remove values not duplicated. However, it only works for values that are only present once.
How would I go on about removing all values that aren't present in this thrice? (or more, in other situations)
The expected result would be:
2 2 5 3 5 3 2 5 3
with 1 and 4 removed, as they are only present twice and once
Reasonably straightforward (longer than using
ave
but possibly more comprehensible):