R gsub a single double quotation mark

后端 未结 1 1263
忘了有多久
忘了有多久 2020-12-11 16:05

I have a field of strings in a data frame all similar to:

\"Young Adult – 8-9\"\" 

where the inner single \" is what I want to repl

相关标签:
1条回答
  • 2020-12-11 17:02

    You do not need to escape a double quote in a regular expression. Just use "\"" or '"' to match a single double quote.

    s = "Young Adult – 8-9\""
    s
    [1] "Young Adult – 8-9\""
    gsub("\"", "", s)
    [1] "Young Adult – 8-9"
    gsub('"', "", s)
    [1] "Young Adult – 8-9"
    

    See this IDEONE demo

    NOTE: Since you want to remove some literal text, you do not even need a regex, use fixed=TRUE argument to speed up the operation:

    gsub('"', "", s, fixed=TRUE)
    
    0 讨论(0)
提交回复
热议问题