我有三个数据框,需要找出拥有小于2个国家的大陆并删除这些国家(行)。这些数据框的结构类似于下面的一个名为x的数据框:
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
首先,我想知道每个大洲的每个国家的频率,所以我进行了以下操作:
x2<-table(x$Continent)
x2
Africa Europe Asia
3 4 2
然后我想识别拥有少于2个国家的大陆。
x3 <- x2[x2 < 10]
x3
Asia
2
我的问题现在是如何删除这些国家。对于上面的例子,将是亚洲的两个国家,我希望我的最终数据集看起来像下面呈现的:
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
拥有少于2个国家的大陆数量在不同数据框中会有所变化,因此我需要一种通用方法来适用于所有数据。
x2[x2<=2]
。 - akrun