【发布时间】:2020-08-05 02:08:03
【问题描述】:
我正在使用 R Studio 分析一项调查。我正在使用 tidytext 包中的 Bing Sentiment 词典来执行此操作。
有些词对我的调查没有正确的含义,特别是“温柔”被编码为正面,但我的受访者将“温柔”表示为负面(疼痛)。我知道如何从 bing tibble 中删除一个词,然后添加一个新词,但我怎样才能简单地改变这个词的含义呢?
例如:
structure(list(word = c("pain", "tender", "sensitive", "headaches",
"like", "anxiety"), sentiment = c("negative", "positive", "positive",
"negative", "positive", "negative"), n = c(351L, 305L, 279L,
220L, 200L, 196L)), row.names = c(NA, 6L), class = "data.frame")
我希望它看起来像:
structure(list(word = c("pain", "tender", "sensitive", "headaches",
"like", "anxiety"), sentiment = c("negative", "negative", "positive",
"negative", "positive", "negative"), n = c(351L, 305L, 279L,
220L, 200L, 196L)), row.names = c(NA, 6L), class = "data.frame")
谢谢!
【问题讨论】:
-
如果您包含一个简单的reproducible example,其中包含可用于测试和验证可能解决方案的示例输入和所需输出,则更容易为您提供帮助。
-
你可以做类似
df$sentiment <- ifelse(df$word == "tender", "positive", df$sentiment)的事情。 -
@MrFlick 我想我已经做了一个可重现的例子!
-
@Phil 这工作得很好!您想将此添加为答案,以便我关闭 Q 吗?