【发布时间】:2018-05-20 10:25:57
【问题描述】:
我有一组来自 Facebook 的 cmets(通过像 Sprinkr 这样的系统提取),其中包含文本和表情符号,我正在尝试在 R 中对它们进行各种分析,但在摄取表情符号时遇到了困难字符正确。
例如:我有一个 .csv(以 UTF-8 编码),它的消息行包含如下内容:
“这是正确的!?!?!请说这是不正确的!我们家只吃原汁原味的Reeses花生酱杯????????????”
然后我通过以下方式将其摄取到 R 中:
library(tidyverse)
library(janitor)
raw.fb.comments <- read_csv("data.csv",
locale = locale(encoding="UTF-8"))
fb.comments <- raw.fb.comments %>%
clean_names() %>%
filter(senderscreenname != "Reese's") %>%
select(c(message,messagetype,sentiment)) %>%
mutate(type = "Facebook")
fb.comments$message[5]
[1] "IS THIS CORRECT!?!?! Please say it isn't true!!! Our family only eats the original Reeses Peanut Butter Cups\xf0\u009f\u0092\u009a\xf0\u009f\u0092\u009a\xf0\u009f\u0092\u009a\n\n"
现在,根据我从其他来源了解到的情况,我需要将这个 UTF-8 转换为 ASCII,然后我可以用它来将它与其他表情符号资源链接起来(比如美妙的 emojidictionary)。为了使连接工作,我需要把它变成 R 编码,像这样:
<e2><9d><a4><ef><b8><8f>
但是,添加正常步骤(使用iconv)并没有让我到达那里:
fb.comments <- raw.fb.comments %>%
clean_names() %>%
filter(senderscreenname != "Reese's") %>%
select(c(message,messagetype,sentiment)) %>%
mutate(type = "Facebook") %>%
mutate(message = iconv(message, from="UTF-8", to="ascii",sub="byte"))
fb.comments$message[5]
[1] "IS THIS CORRECT!?!?! Please say it isn't true!!! Our family only eats the original Reeses Peanut Butter Cups<f0><9f><92><9a><f0><9f><92><9a><f0><9f><92><9a>\n\n"
那里的任何人都可以告诉我我缺少什么,或者我需要找到不同的表情符号映射资源吗?谢谢!
【问题讨论】:
-
你能显示
dput(fb.comments$message[5])吗? -
dput(fb.comments$message[5]) "IS THIS CORRECT!?!?! Please say it isn't true!!! Our family only eats the original Reeses Peanut Butter Cups<f0><9f><92><9a><f0><9f><92><9a>0><9f><92><9a>\n\n" -
在 mutate-iconv 之前?
-
啊,是的!对不起!
dput(fb.comments$message[5]) "IS THIS CORRECT!?!?! Please say it isn't true!!! Our family only eats the original Reeses Peanut Butter Cups<f0><U+009F><U+0092><U+009A><f0><U+009F><U+0092><U+009A><f0><U+009F><U+0092><U+009A>\n\n"
标签: r text unicode utf-8 emoji