How to delete rows in a data frame after frequency tables in R

I have 3 data frames from which I have to find a continent with less than two countries and delete these countries (rows). Data frames are structured in the same way as a data frame, called x below:

    row        Country   Continent   Ranking
    1        Kenya       Africa      17
    2        Gabon       Africa      23
    3        Spain       Europe      04
    4        Belgium     Europe      03
    5        China       Asia        10
    6        Nigeria     Africa      14
    7        Holland     Europe      01
    8        Italy       Europe      05
    9        Japan       Asia        06
At first I wanted to know the frequency of each country on the continent, so I did
    x2<-table(x$Continent)
    x2
    Africa Europe Asia
    3        4      2

Then I wanted to identify continents with less than two countries.

    x3 <- x2[x2 < 10]
    x3
    Asia
    2  

Now my problem is how to remove these countries. In the example above, these will be two countries in Asia, and I want my latest dataset to look like this:

    row       Country   Continent   Ranking
    1        Kenya       Africa      17
    2        Gabon       Africa      23
    3        Spain       Europe      04
    4        Belgium     Europe      03
    5        Nigeria     Africa      14
    6        Holland     Europe      01
    7        Italy       Europe      05

The number of continents with less than two countries will vary between different data frames, so I need one universal method that I can apply to everyone.

+4
2

Try

 library(dplyr)
 x %>%
    group_by(Continent) %>% 
    filter(n()>2)
 #   row Country Continent Ranking
 #1   1   Kenya    Africa      17
 #2   2   Gabon    Africa      23
 #3   3   Spain    Europe      04
 #4   4 Belgium    Europe      03
 #5   6 Nigeria    Africa      14
 #6   7 Holland    Europe      01
 #7   8   Italy    Europe      05

x2

 subset(x, Continent %in% names(x2)[x2>2])
 #    row Country Continent Ranking
 #1   1   Kenya    Africa      17
 #2   2   Gabon    Africa      23
 #3   3   Spain    Europe      04
 #4   4 Belgium    Europe      03
 #6   6 Nigeria    Africa      14
 #7   7 Holland    Europe      01
 #8   8   Italy    Europe      05
+4

"data.table":

library(data.table)
as.data.table(x)[, N := .N, by = Continent][N > 2]
#    row Country Continent Ranking N
# 1:   1   Kenya    Africa      17 3
# 2:   2   Gabon    Africa      23 3
# 3:   3   Spain    Europe       4 4
# 4:   4 Belgium    Europe       3 4
# 5:   6 Nigeria    Africa      14 3
# 6:   7 Holland    Europe       1 4
# 7:   8   Italy    Europe       5 4

R :

x[with(x, ave(rep(TRUE, nrow(x)), Continent, FUN = function(y) length(y) > 2)), ]
#   row Country Continent Ranking
# 1   1   Kenya    Africa      17
# 2   2   Gabon    Africa      23
# 3   3   Spain    Europe       4
# 4   4 Belgium    Europe       3
# 6   6 Nigeria    Africa      14
# 7   7 Holland    Europe       1
# 8   8   Italy    Europe       5
+3

All Articles