简体   繁体   English

R:如果值不在另一个列表中,则过滤 dataframe 行

[英]R: filter dataframe rows if values are not in another list

I have a dataframe with the following structure:我有一个具有以下结构的 dataframe:

     Element     Error
1    A           Grid error
2    B           Meteo error
3    C           Gen error
4    D           Blade error

I would like to filter it, keeping only the rows in which the values in the Error column are not in the following list ["Grid error", "Meteo error"]我想过滤它,只保留Error列中的值不在以下列表中的行["Grid error", "Meteo error"]

So my expected output is:所以我预期的 output 是:

     Element     Error
1    C           Gen error
2    D           Blade error

Using subset from base R使用来自base Rsubset

 subset(data, !Error %in% c("Grid error","Meteo error"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM