I have some race data where the values contain ‘\n’, such as in ‘Biracial or Multiracial\nBlack or African American\nWhite or Caucasian’ or ‘White or Caucasian\nBlack or African American’. Is there a way to remove the slash and the followed letter n? (preferably using str_remove or gsub)
>Solution :
You can use double \ for escaping.
For instance:
library(stringr)
str_remove("Multiracial\nBlack" , "\\n")
And the same for gsub():
gsub("\\n", "", "Multiracial\nBlack")
Output:
[1] "MultiracialBlack"
I hope you consider \n to be line brake, not two symbols.