使用 tm 包删除 R 中的表情符号

Lui*_*uis 4 r emoticons sentiment-analysis tm

我正在使用 tm 包来清理 Twitter 语料库。但是,该软件包无法清理表情符号。

\n\n

这是复制的代码:

\n\n
July4th_clean <- tm_map(July4th_clean, content_transformer(tolower))\nError in FUN(content(x), ...) : invalid input 'RT ElleJohnson Love of country is encircling the globes \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd july4thweekend July4th FourthOfJuly IndependenceDay NotAvailableOnIn' in 'utf8towcs'\n
Run Code Online (Sandbox Code Playgroud)\n\n

有人可以指出我使用 tm 包删除表情符号的正确方向吗?

\n\n

谢谢你,

\n\n

路易斯

\n

G5W*_*G5W 8

您可以使用gsub来删除所有非 ASCII 字符。

\n\n
Texts = c("Let the stormy clouds chase, everyone from the place \xe2\x98\x81  \xe2\x99\xaa \xe2\x99\xac",\n    "See you soon brother \xe2\x98\xae ",\n    "A boring old-fashioned message" ) \n\ngsub("[^\\x01-\\x7F]", "", Texts)\n[1] "Let the stormy clouds chase, everyone from the place    "\n[2] "See you soon brother  "                                  \n[3] "A boring old-fashioned message"\n
Run Code Online (Sandbox Code Playgroud)\n\n

详细信息: \n您可以使用 .regex 在正则表达式中指定字符类[ ]。当类描述以它开头时,^它表示除这些字符之外的所有内容。在这里,我指定了除字符 1-127 之外的所有内容,即除标准 ASCII 之外的所有内容,并且我已指定它们应替换为空字符串。

\n