根据满足条件的行数对数据框进行子集

时间:2021-06-17 15:37:15

标签: r subset data-cleaning data-wrangling

如果一个观察值超过 3 行,有没有办法对我的数据框进行子集化?例如。我的数据看起来像:

ID    Food        Vegetable 
aaa   fruit       lemon 
bbb   fruit       lemon
ccc   fruit       sprout
ddd   fruit       lemon
eee   fruit       lemon
fff   fruit       watermelon

我希望它看起来像:

ID    Food        Vegetable 
aaa   fruit       lemon 
bbb   fruit       lemon
ddd   fruit       lemon
eee   fruit       lemon

   

结构:

structure(list(ID = c("aaa", "bbb", "ccc", "ddd", "eee", "fff"
    ), Food = c("fruit", "fruit", "fruit", "fruit", "fruit", "fruit"), Vegetable = c("lemon", 
    "lemon", "sprout", "lemon", "lemon", "watermelon")), class = "data.frame", row.names = c(NA, 
    -6L))

谢谢

0 个答案:

没有答案