【问题标题】:Operation between 2 data frames in RR中2个数据帧之间的操作
【发布时间】:2015-11-08 21:42:53
【问题描述】:

我有这个数据框:

 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')

如何制作一个获取每个分的“分数”的数据框:

                         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

【问题讨论】:

    标签: r text dataframe nlp


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2018-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多