用 gsub 替换特殊字符

Replace special characters with gsub

有没有办法用gsub替换R中的特殊字符串? 我有几列其中包含 \n,我希望将其更改为 \n 但 gsub 不起作用

这是一个例子:

gsub("\n", "\n", "\n this is a test \n data")

我收到以下输出:

[1] "\n this is a test \n data"

您可以通过在 gsub 命令末尾添加参数 fixed=T 来执行您想要的操作。

gsub("\n", "\n", "\n this is a test \n data",fixed=T)
[1] "\n this is a test \n data"