Reputation: 33
I want to eliminate double quotes from text in R. Is there a better way to do it? I tried below code but it's still not removing double quotes:
gsub("\"", "", a$answer)
Upvotes: 1
Views: 296
Reputation: 887851
We can also do this without escaping the double quotes
gsub('"', "gone!", withquotes)
#[1] " this is a double quote: gone! "
withquotes <- ' this is a double quote: " '
Upvotes: 0
Reputation: 44977
The problem with what you tried is that you want the regular expression (i.e. pattern) to be \"
, but backslashes are special to R, so you need to write it twice in R so it ends up as a single backslash in the pattern.
For example,
withquotes <- ' this is a double quote: " '
gsub('\\"', "gone!", withquotes)
# [1] " this is a double quote: gone! "
Upvotes: 2