Description Usage Arguments Details Value References Examples
View source: R/tidy_net_sentiment_nrc.R
Order result of calc_net_sentiment_nrc
by the
count of one or more NRC sentiments, and convert to "tidy" format.
1 2 3 4 5 | tidy_net_sentiment_nrc(
net_sentiment_wide_nrc,
sorting_sentiments = "anger",
num_of_docs = 60
)
|
net_sentiment_wide_nrc |
A data frame/tibble derived from
|
sorting_sentiments |
A string of vector of strings with the NRC
sentiments (Mohammad & Turney, 2013) by which to sort the returned table.
(To see all NRC sentiments run |
num_of_docs |
The number of document IDs for which to return results. See details. |
The returned data frame will have, for each document (or class- see
filter_class
in calc_net_sentiment_nrc
), as many rows
as the NRC sentiments with non-zero counts (remember- this function
returns the result in long format). If all sentiments have non-zero
counts in a given document, then there will be 10 rows (as many as all
the NRC sentiments) in the returned data frame for this document.
Argument num_of_docs
returns the first num_of_docs
documents
(or classes, see filter_class
in calc_net_sentiment_nrc
),
with the top one being the one that has the highest count(s) of the NRC
sentiment(s) specified in sorting_sentiments
.
A data frame in long format with four columns: the text; the line number; the NRC sentiment; and the count of the NRC sentiment.
Mohammad S.M. & Turney P.D. (2013). Crowdsourcing a Word–Emotion Association Lexicon. Computational Intelligence, 29(3):436-465.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | library(experienceAnalysis)
books <- janeaustenr::austen_books() # Jane Austen books
emma <- paste(books[books$book == "Emma", ], collapse = " ") # String with whole book
pp <- paste(books[books$book == "Pride & Prejudice", ], collapse = " ") # String with whole book
# Make data frame with books Emma and Pride & Prejudice
x <- data.frame(
text = c(pp, emma),
book = c("Pride & Prejudice", "Emma")
)
# Net sentiment in each book
net_sentiment_wide_nrc <- calc_net_sentiment_nrc(x, target_col_name = "book",
text_col_name = "text",
filter_class = NULL)
net_sentiment_wide_nrc
# Tidy net_sentiment_wide_nrc and place the most "angry" book at the top
tidy_net_sentiment_nrc(net_sentiment_wide_nrc,
sorting_sentiments = "anger",
num_of_docs = 2) %>%
dplyr::select(-text)
# Can sort by multiple sentiments too: as above, but for most "angry" and then for most "negative"
tidy_net_sentiment_nrc(net_sentiment_wide_nrc,
sorting_sentiments = c("anger", "negative"),
num_of_docs = 2) %>%
dplyr::select(-text)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.