1

I want to remove the rows of a data frame that meet certain conditions based on 2 columns:

  1. contain _text1 in Column1
  2. don't have text2 exact match in Column2

I've managed to find a way to filter the rows I want to remove with the below code:

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

but I can't think of a way to reverse the code in order give me back the rows I want to keep, by simultaneously satisfying both conditions.

nba2020
  • 618
  • 1
  • 8
  • 22
  • 2
    You can use `!` to negate the expression (if that's what you're trying to do, your question is a bit unclear): `Table%>%filter(! (str_detect(Column1, '_text1') & Column2!="text2") )` – bouncyball Aug 21 '19 at 13:27
  • Thanks! Nesting both conditions !(conditions) did the trick. I wasn't aware this was possible to do. Thank you so much !!!! :) :) – nba2020 Aug 21 '19 at 13:34

1 Answers1

0

I can't test my answer because you did not provide a reproducible example, but, if I understood you correctly, you can simply negate your condition:

Table%>%filter(!(str_detect(Column1, '_text1') & Column2!="text2"))
slava-kohut
  • 4,203
  • 1
  • 7
  • 24