rows - remove IDs that occur x times R -


i have df , remove people have less x amount of rows in df. e.g., in toy example, retain people have >= 5 rows.

df    names  fruit 4   john   kiwi 7   john  apple 9   john banana 13  john orange 14  john  apple 2   mary orange 5   mary  apple 8   mary orange 10  mary  apple 12  mary  apple 1    tom  apple 3    tom banana 6    tom  apple 11   tom   kiwi 

example output

df    names  fruit 4   john   kiwi 7   john  apple 9   john banana 13  john orange 14  john  apple 2   mary orange 5   mary  apple 8   mary orange 10  mary  apple 12  mary  apple 

thanks in advance!

you can use table this:

df[df$names %in% names(table(df$names))[table(df$names) >= 5],] 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo