Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Filter rows which does NOT contain a certain string

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

You can simply use ! before your grepl like this:

df <- df %>% filter(!grepl('first|second', Text))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading