【问题标题】:R: remove rows with a combination of text conditions in 2 columnsR:删除具有 2 列中文本条件组合的行
【发布时间】:2019-08-21 13:24:58
【问题描述】:

我想根据 2 列删除满足特定条件的数据框行:

  1. Column1 中包含_text1
  2. Column2 中没有text2 完全匹配

我已经设法找到一种方法来过滤我想用下面的代码删除的行:

Table%>%filter(str_detect(Column1, '_text1') & Column2!="text2")

但我想不出一种方法来反转代码,以便通过同时满足两个条件来返回我想要保留的行。

【问题讨论】:

  • 您可以使用! 来否定表达式(如果这是您想要做的,您的问题有点不清楚):Table%>%filter(! (str_detect(Column1, '_text1') & Column2!="text2") )
  • 谢谢!嵌套两个条件!(条件)就可以了。我不知道这是可能的。非常感谢 !!!! :) :)

标签: r dplyr


【解决方案1】:

我无法测试我的答案,因为您没有提供reproducible example,但是,如果我理解正确,您可以简单地否定您的条件:

Table%>%filter(!(str_detect(Column1, '_text1') & Column2!="text2"))

【讨论】:

    猜你喜欢
    • 2021-08-17
    • 1970-01-01
    • 2021-10-23
    • 1970-01-01
    • 2021-11-25
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多