0

I have a data.frame with 1 column, and a nondescript number of rows.

This column contains strings, and some strings contain a substring, let's say "abcd".

I want to remove any strings from the database that contain that substring. For example, I may have five strings that are "123 abcd", and I want those to be removed.

I am currently using grepl() to try and remove these values, but it is not working. I am trying:

data.frame[!grepl("abcd", dataframe)]

but it returns an empty data frame.

divibisan
  • 11,659
  • 11
  • 40
  • 58
  • Share reproducible data. Here are some tips: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example?rq=1 – s_baldur Aug 17 '18 at 13:45

1 Answers1

0

We can use grepl to get a logical vector, negate (!) it, and use that to subset the 'data'

data[!grepl("abcd", data$Col),,drop = FALSE]
akrun
  • 874,273
  • 37
  • 540
  • 662