-9

I am struck with the problem, where i want to blank out the row, if it begins certain word, from below example, i want to blank out the entries which begins with "error"

Input:

TESTNumber
errorCode404errorMessage
TESTNumber
TESTNumber
TESTNumber
TESTNumber
TESTNumber
TESTNumber
TESTNumber
TESTNumber
TESTNumber
TESTNumber
TESTNumber
TESTNumber
TESTNumber
TESTNumber
TESTNumber
TESTNumber
errorCode404errorMessage
errorCode404errorMessage
errorCode404errorMessage

Any guidance in this direction will be great support.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 1
    What did you try, and how did it fail? This is probably a duplicate. – tripleee Oct 12 '17 at 12:59
  • Consider edit your question after reading [this](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and adding more information. As tripleee said, this looks like a duplicate to begin with, so you should maybe start with searching for your answer. The related links on the side of your question is a good place to start. – shea Oct 12 '17 at 13:01
  • try `grepl()` to get the indices where condition matches and then remove the indexes. – tushaR Oct 12 '17 at 13:04

1 Answers1

2

Quick data:

df <- data.frame("var1" = 1:2, "var2" = c("testest", "errorTtest"))

> df
  var1       var2
1    1    testest
2    2 errorTtest

Now use grepl() with the pattern "^error.*" to get the positions of all rows with error in the beginning of var2, use which with - to delete them from the data.

> df[-(which(grepl("^error.*", df$var2))),]
  var1    var2
1    1 testest
LAP
  • 6,605
  • 2
  • 15
  • 28