使用 tm 包删除 R 中的表情符号
remove emoticons in R using tm package
我正在使用 tm 包清理 Twitter 语料库。但是,该软件包无法清理表情符号。
这是一个复制代码:
July4th_clean <- tm_map(July4th_clean, content_transformer(tolower))
Error in FUN(content(x), ...) : invalid input 'RT ElleJohnson Love of country is encircling the globes ������������������ july4thweekend July4th FourthOfJuly IndependenceDay NotAvailableOnIn' in 'utf8towcs'
有人可以指出我使用 tm 包删除表情符号的正确方向吗?
谢谢,
路易斯
你可以试试这个功能
iconv(July4th_clean, "latin1", "ASCII", sub="")
重复问题,see post
您可以使用 gsub
删除所有非 ASCII 字符。
Texts = c("Let the stormy clouds chase, everyone from the place ☁ ♪ ♬",
"See you soon brother ☮ ",
"A boring old-fashioned message" )
gsub("[^\x01-\x7F]", "", Texts)
[1] "Let the stormy clouds chase, everyone from the place "
[2] "See you soon brother "
[3] "A boring old-fashioned message"
详情:
您可以在带有 [ ]
的正则表达式中指定字符 classes。当 class 描述以 ^
开头时,它表示所有 除了 这些字符。在这里,我指定了除字符 1-127 之外的所有内容,即除了标准 ASCII 之外的所有内容,并且我指定了它们应该被替换为空字符串。
我正在使用 tm 包清理 Twitter 语料库。但是,该软件包无法清理表情符号。
这是一个复制代码:
July4th_clean <- tm_map(July4th_clean, content_transformer(tolower))
Error in FUN(content(x), ...) : invalid input 'RT ElleJohnson Love of country is encircling the globes ������������������ july4thweekend July4th FourthOfJuly IndependenceDay NotAvailableOnIn' in 'utf8towcs'
有人可以指出我使用 tm 包删除表情符号的正确方向吗?
谢谢,
路易斯
你可以试试这个功能
iconv(July4th_clean, "latin1", "ASCII", sub="")
重复问题,see post
您可以使用 gsub
删除所有非 ASCII 字符。
Texts = c("Let the stormy clouds chase, everyone from the place ☁ ♪ ♬",
"See you soon brother ☮ ",
"A boring old-fashioned message" )
gsub("[^\x01-\x7F]", "", Texts)
[1] "Let the stormy clouds chase, everyone from the place "
[2] "See you soon brother "
[3] "A boring old-fashioned message"
详情:
您可以在带有 [ ]
的正则表达式中指定字符 classes。当 class 描述以 ^
开头时,它表示所有 除了 这些字符。在这里,我指定了除字符 1-127 之外的所有内容,即除了标准 ASCII 之外的所有内容,并且我指定了它们应该被替换为空字符串。