View source: R/textstat_valence.R
valence | R Documentation |
Set or retrieve the valences of a dictionary object for the purposes of
sentiment analysis. Valences consist of numerical values attached to each
dictionary "value". For dictionaries with a more "polarity"-based approach,
see textstat_polarity()
valence(x)
valence(x) <- value
x |
a quanteda dictionary object |
value |
named list consisting of numerical value. The names of the elements must correspond to a dictionary key. Each element must be:
|
Valences are used only in textstat_valence()
.
A dictionary may have only one set of valences at a time, but may be changed as needed.
valences()
returns the valences as a list named numeric vectors,
where each list element corresponds to a key in the dictionary, and each
numeric element matches a value within that key.
valence<-
sets the dictionary's valences.
textstat_valence()
, valence()
library("quanteda")
# setting valences
dict <- dictionary(list(
happiness = c("happy", "jubilant", "exuberant", "content"),
anger = c("mad", "peeved", "irate", "furious", "livid")
))
valence(dict)
# using a 5-point scale: 1:1 match
valence(dict) <- list(happiness = c(3, 4, 5, 2),
anger = c(3.1, 2.4, 2.9, 4.1, 5.0))
valence(dict)
# with single valences applied to all values within the keys
valence(dict) <- c(happiness = 1, anger = -1)
valence(dict)
# with named elements - order does not matter
valence(dict) <- list(
happiness = c(exuberant = 5, jubilant = 4, happy = 3, content = 2)
)
valence(dict)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.