【问题标题】:What does \\n means and how to remove it? [duplicate]\\n 是什么意思以及如何删除它? [复制]
【发布时间】:2021-01-20 07:09:12
【问题描述】:

我有一个数据集,应该清理它。我的数据中的一个例子:

new<-"\\nLocation:\\nMy home is conveniently located around the corner from the Galleria Mall. There's an abundance of food options in every direction of my place. There are also 2 movie theaters within 5 minute driving distance. Addison which is known for their restaurants and nightlife is a 5 minute drive.\\n-DFW  ; Lovefield Airport 20min\\n-American Airlines Center 15min\\n-Downtown 15min\\n-Deep Ellum, Lower Greenville, Uptown 20min"

我尝试使用这个功能:

str_replace_all(new, "[\n]", "") 

但它不起作用。

我的问题:

  1. \n 和 \\n 有什么区别
  2. 如何删除?

【问题讨论】:

  • 1.) 要了解区别,请将cat("\n")cat("\\n") 进行比较。当这些被传递给正则表达式引擎时,也会发生同样的情况。

标签: r data-cleaning


【解决方案1】:

'\n' 是换行符,而'\\n' 是转义的反斜杠,后跟'n'

您可以使用gsub 删除它:

gsub('\\\\n', '', new)

【讨论】:

    猜你喜欢
    • 2013-08-04
    • 2016-02-26
    • 1970-01-01
    • 2012-07-22
    • 2010-11-22
    • 2015-02-02
    • 2021-09-16
    • 2018-02-17
    • 1970-01-01
    相关资源
    最近更新 更多