Learn R Programming

sentimentr (version 0.4.0)

extract_sentiment_terms: Extract Sentiment Words

Description

Extract the sentiment words from a text.

Usage

extract_sentiment_terms(text.var, polarity_dt = sentimentr::polarity_table, hyphen = "", ...)

Arguments

text.var
The text variable.
polarity_dt
A data.table of positive/negative words and weights with x and y as column names.
hyphen
The character string to replace hyphens with. Default replaces with nothing so 'sugar-free' becomes 'sugarfree'. Setting hyphen = " " would result in a space between words (e.g., 'sugar free').
...
ignored.

Value

Returns a data.table with columns of positive and negative terms.

Examples

Run this code
library(data.table)
set.seed(10)
x <- sample(cannon_reviews[[3]], 3000, TRUE)
sentiment(x)

pol_words <- extract_sentiment_terms(x)
pol_words
pol_words$sentence
pol_words$neutral
data.table::as.data.table(pol_words)

attributes(extract_sentiment_terms(x))$counts
attributes(extract_sentiment_terms(x))$elements

Run the code above in your browser using DataLab