0

I am trying to delete all the rows in a Dataframe with the string "$null$". I was trying to use the following code to achieve that for a column called "resale". Can someone please tell me what I might be doing wrong here.

cars3 <- cars_2[!grepl("$null$", cars_2$resale),]
Jitendra
  • 307
  • 2
  • 3
  • 9

2 Answers2

3

$ is a regex metacharacter, indicating the string-last position. If you refer to it literally, you need to escape it:

 cars3 <- cars_2[!grepl("\\$null\\$", cars_2$resale),]
Chris Ruehlemann
  • 20,321
  • 4
  • 12
  • 34
2

Try with fixed = TRUE

cars3 <- cars_2[grep("$null$", car2_2$resale, fixed = TRUE, invert = TRUE),]
akrun
  • 874,273
  • 37
  • 540
  • 662