df:-
Date Name Salary
Q1 2015 ABC $10
Q2 2015 ABC $11
Q3 2015 ABC $15
Q1 2015 XYZ $25
Q2 2015 XYZ $20
I want to remove the rows from the data whose total frequency is less than 3. For e.g. XYZ have a frequency of 2 and so I want to remove row 4 and 5.
test <- setDT(df)[,.I[.N>2],by=Name]
Output:-
> test
Name V1
1: ABC 1
2: ABC 2
3: ABC 3
Filtering is done correctly but I don't get the whole data set, I only get the Name column in the output.