Difference between revisions of "R: sentiments analysis"
Jump to navigation
Jump to search
Onnowpurbo (talk | contribs) |
Onnowpurbo (talk | contribs) |
||
| Line 13: | Line 13: | ||
library(dplyr) | library(dplyr) | ||
library(stringr) | library(stringr) | ||
| − | |||
tidy_books <- austen_books() %>% | tidy_books <- austen_books() %>% | ||
group_by(book) %>% | group_by(book) %>% | ||
| Line 22: | Line 21: | ||
unnest_tokens(word, text) | unnest_tokens(word, text) | ||
| + | |||
| + | |||
| + | nrcjoy <- get_sentiments("nrc") %>% | ||
| + | filter(sentiment == "joy") | ||
| + | tidy_books %>% | ||
| + | filter(book == "Emma") %>% | ||
| + | inner_join(nrcjoy) %>% | ||
| + | count(word, sort = TRUE) | ||
Revision as of 16:58, 8 November 2018
library(tidytext) sentiments
get_sentiments("afinn")
get_sentiments("bing")
get_sentiments("nrc")
library(janeaustenr)
library(dplyr)
library(stringr)
tidy_books <- austen_books() %>%
group_by(book) %>%
mutate(linenumber = row_number(),
chapter = cumsum(str_detect(text, regex("^chapter [\\divxlc]",
ignore_case = TRUE)))) %>%
ungroup() %>%
unnest_tokens(word, text)
nrcjoy <- get_sentiments("nrc") %>%
filter(sentiment == "joy")
tidy_books %>%
filter(book == "Emma") %>%
inner_join(nrcjoy) %>%
count(word, sort = TRUE)