0

I have a data set and should clean it. One example from my data:

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"

I tried to use this function:

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

But it does not work.

My questions:

  1. What difference between \n and \\n
  2. How to remove it?
Ekaterina
  • 69
  • 8
  • 1
    1.) To understand the difference, compare `cat("\n")` with `cat("\\n")`. When these are passed to the regex engine, the same happens. – Roland Jan 20 '21 at 07:25

1 Answers1

1

'\n' is a new line character whereas '\\n' is an escaped backslash followed by 'n'.

You can remove it by using gsub :

gsub('\\\\n', '', new)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213