0

Considering that I have a dataframe (3+ Million rows) (df) with a column named as Text containing a sentence in each row. I want to filter the data in a way that it excludes those rows which have certain keywords.

I know that if you want to filter a dataframe if it has some certain strings you can do as follows:

df <- df %>% filter(grepl('first|second', Text))

And this will filter the rows including first and second as keywords only.

How can I filter the rows excluding the above two keywords?

AneesBaqir
  • 423
  • 1
  • 12

1 Answers1

2

You can simply use ! before your grepl like this:

df <- df %>% filter(!grepl('first|second', Text))
Quinten
  • 35,235
  • 5
  • 20
  • 53