我是R.的新手。我在文档中找到了正面否定词的数量(953个否定,458个正数),但我希望看到这些词。我该怎么做?
library(readr)
library(tidyverse)
library(tidytext)
library(glue)
library(stringr)
library(dplyr)
davos <- read_file("davos.txt")
fileText <- glue(read_file(davos))
fileText <- gsub("\\$", "", fileText)
tokens <- data_frame(text = fileText) %>% unnest_tokens(word, text)
tokens %>% inner_join(get_sentiments("bing")) %>% count(sentiment) %>% spread(sentiment, n, fill = 0) %>% mutate(sentiment = positive - negative)
# Joining, by = "word"
#
# # A tibble: 1 x 3
# negative positive sentiment
# <dbl> <dbl> <dbl>
# 1 953. 458. -495.
答案 0 :(得分:3)
这样的东西?
library(tidy_text)
fileText <- "Sometimes I'm happy, sometimes I'm sad"
tokens <- data_frame(text = fileText) %>% unnest_tokens(word, text)
tokens %>%
inner_join(get_sentiments("bing"))
# # A tibble: 2 x 2
# word sentiment
# <chr> <chr>
# 1 happy positive
# 2 sad negative