I have this text and I want to replace //
with \
This is the text sdfd//dfsadfs
and I want it to be sdfd\dfsadfs
Can gsub work? This does not work: gsub("//","[\]","sdfd//dfsadfs")
I have this text and I want to replace //
with \
This is the text sdfd//dfsadfs
and I want it to be sdfd\dfsadfs
Can gsub work? This does not work: gsub("//","[\]","sdfd//dfsadfs")
I had a similar problem before. Like @Psidom commented, you should use gsub("//","\\\\","sdfd//dfsadfs")
. This will replace //
(2 characters) with \\
which is actually a single character in R (Check by running nchar("\\")
). Even though it is prints as \\
, it behaves as \
. You can check this by running cat("\\")
. If you exported the data after running gsub
to a table (or csv), I believe there will be only one \