提取情感数据框

时间:2018-09-29 21:10:03

标签: r tidyr

如何使用整洁的诗句提取一个包含5列情绪悲伤,愤怒,喜悦,中立的爱的数据框?

预期输出示例

id text sadness anger joy love neutral
11 "bad movie" 1 0 0 0 0
12 "good movie" 0 0 1 0 0 

直到现在我一直尝试:

library(tidyr)
text = data.frame(id = c(11,12), text=c("bad movie","good movie"))
nrc_lexicon <- get_sentiments("nrc")

1 个答案:

答案 0 :(得分:0)

tribbles很好

library(tidyverse)

df <- tribble(
~id, ~text,       ~sadness, ~anger, ~joy, ~love, ~neutral,
11,   "bad movie",   1,       0,      0,      0,    0,
12,   "good movie",  0,       0,      1,      0,    0)

df

#> # A tibble: 2 x 7
#>      id text       sadness anger   joy  love neutral
#>   <dbl> <chr>        <dbl> <dbl> <dbl> <dbl>   <dbl>
#> 1    11 bad movie        1     0     0     0       0
#> 2    12 good movie       0     0     1     0       0

```

reprex package(v0.2.1)于2018-09-29创建