R: How to replace . in a string?
r, regex
Solution
`.` matches any character. Escape `.` using `\` to match `.` literally.
`\` itself is also should be escaped:
> gsub("\\.", "_", "a.b")
[1] "a_b"
Problem
I have a string say "a.b" and I want to replace "." with "_". ``` gsub(".","_","a.b") ``` doesn't work as . matches all characters. ``` gsub("\.","_","a.b") ``` Just gives me an error. Reading the documentation on ?gsub is not that helpful! So how to do this straight-forward thing?