我有这个数据框:
word value
very good 2
this is 2
we are -1
very bad -2
.
.
.
和
Sentences <- c('good good','very good very bad','we are we are','very good very good very bad')
如何制作一个取得&#39;得分的数据框?每个中心:
Sentences score
1 good good 0
2 very good very bad 0
3 we are we are -2
4 very good very good very bad 2
答案 0 :(得分:1)
你可以尝试:
library(stringr)
data.frame(Sentences, score=sapply(Sentences, function(x) sum(str_count(x, score$word)*score$value)), row.names = NULL)
Sentences score
1 good good 0
2 very good very bad 0
3 we are we are -2
4 very good very good very bad 2