我有这样的字符串:
x <- c("saw the revenant awesome experience must be seen on a big theatrical screen\ntherevenant","a lil sumn sumn i whipped up \U3e64653c\U3e30613c\U3e64623c\U3e64653c\U3e36623c\U3e61383ctherevenant")
如何使用gsub()?
删除R中以\ n或\ U开头的所有内容答案 0 :(得分:3)
您可以使用iconv
删除\ U字符和gsub
来处理换行符。
x <- c("saw the revenant awesome experience must be seen on a big theatrical screen\ntherevenant","a lil sumn sumn i whipped up \U3e64653c\U3e30613c\U3e64623c\U3e64653c\U3e36623c\U3e61383ctherevenant")
> iconv(gsub("\\n", " ", x), to="ASCII", sub="")
[1] "saw the revenant awesome experience must be seen on a big theatrical screen therevenant"
[2] "a lil sumn sumn i whipped up therevenant"