在 R 中删除以 \n 或 \U 开头的字符串
Remove a string starting with \n or \U in R
我有这样的字符串:
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 开头的所有内容?
您可以使用 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"
我有这样的字符串:
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 开头的所有内容?
您可以使用 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"