代码之家  ›  专栏  ›  技术社区  ›  KRStam

用gsub替换特殊字符

  •  4
  • KRStam  · 技术社区  · 6 年前

    有没有办法用gsub替换R中的特殊字符串? 我有几个专栏 \\n 我想把它改成 \n 但gsub不起作用

    以下是一个示例:

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

    我收到以下输出:

    [1] "\\n this is a test \\n data"
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   xraynaud    6 年前

    您可以通过在gsub命令的末尾添加参数fixed=T来完成所需的操作。

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