0

Does anybody knows how can i replace "\" in r?

Other answers have posted something like:

l <- "1120190\neconomic"
gsub("\\", "", l, fixed=TRUE)

But didn't work in my case.

  • 1
    This is not a backslash, it's a newline character (`\n`). You can use `gsub("\n", "", l)` if you need to remove it. – Ritchie Sacramento Jan 21 '20 at 02:18
  • I have reopened this question because it was edited and is now apparently not a duplicate of "replace a backslash". But I'm sure there's a duplicate for "replace a newline". – neilfws Jan 21 '20 at 02:43
  • hello, can you use `cat` eg `cat(l)` do you see any backslash? – Onyambu Jan 21 '20 at 03:22

1 Answers1

0

The \n is a symbol for newline and if you want to replace it with space you can use the following:

l <- "1120190\neconomic"
cat(l)
gsub("\n", " ", l, fixed=TRUE)

Note, that the output would be:

1120190
economic
[1] "1120190 economic"
m0nhawk
  • 22,980
  • 9
  • 45
  • 73