Using gsub()
, I want to replace "nn" to "" in this text:
mystring<-"People Storm Seonul Airport as Citizens Leave\n\nCHOI JEONGHO\n\nSEOUL, South Korea, Jan. 31"
But, when I ran gsub("[r\n]", " ", mystring)
, it deletes all n in the text.
The output was:
"People Storm Seo ul Airport as Citize s Leave CHOI JEO GHO SEOUL, South Korea, Ja . 31"
Could you teach me why it is so and how to delete only "nn"?
2
Answers
n
s.\n
, you need to escape both backslashes, giving you\\n
.Here’s an option with the
stringr
package. In R, you need to escape backslashes using\
, so you’ll need to use\\n
as your argument: