Remove double quote \" symbol from string
You can try this. Note that what you actually want is to remove \"
, not "\
(as proposed in the unedited version of your question). The first "
you need to represent each element in the character.
gsub('[\"]', '', data)
If it is always 1st character then just use substring:
substring(data, 2)
This should be faster than any regex solution.
data <- rep(data, 1000)
microbenchmark::microbenchmark(
a = substring(data, 2),
b = gsub("\"", "", data, fixed = TRUE),
c = gsub('"', "", data),
d = gsub('[\"]', '', data),
e = stringr::str_replace(data, '[\"]', ''),
f = gsub("^.","",data)
)
# Unit: milliseconds
# expr min lq mean median uq max neval
# a 2.835013 2.849838 2.933796 2.857393 2.900301 4.446956 100
# b 4.728632 4.739751 4.788882 4.754861 4.795203 5.200185 100
# c 7.388025 7.413684 7.503427 7.458444 7.555520 8.160925 100
# d 7.390876 7.412686 7.530044 7.454453 7.533568 8.535544 100
# e 12.019154 12.205608 12.430870 12.316084 12.581081 13.917336 100
# f 15.712882 15.735975 15.875353 15.770043 15.861275 18.906262 100
Use fixed = TRUE
to match the pattern as a string:
gsub("\"", "", data, fixed = TRUE)
Or we can just use '"'
on the pattern
gsub('"', "", data)