小编Neu*_*xis的帖子

替代 R 中的子集?

例如,我有 5 个州和每个州的多个城市。我想每个州只选择 1 个城市。我正在尝试这个代码:

country <- subset(country, country$state == "1" & country$city == "1" |  
                           country$state == "2" & country$city == "4" |
                           country$state == "3" & country$city == "3" | 
                           country$state == "4" & country$city == "2" |
                           country$state == "5" & country$city == "101")
Run Code Online (Sandbox Code Playgroud)

有没有另一种方法可以做到这一点?我发现这段代码非常丑陋且不理想。

r subset

3
推荐指数
1
解决办法
64
查看次数

标签 统计

r ×1

subset ×1