sentiment_scores_r: Sentiment analysis with Python packages

Description Usage Arguments Details Value Examples

View source: R/sentiment_scores_r.R

Description

Calculate sentiment indicators from TextBlob and vaderSentiment.

Usage

1

Arguments

x

Data frame. The text to run sentiment analysis on.

Details

This function complements existing sentiment analysis packages in R (e.g. tidytextor quanteda.sentiment) with the popular Python sentiment analysis libraries TextBlob and vaderSentiment.

TextBlob calculates two indicators, namely polarity and subjectivity. The polarity score is a float within the range [-1, 1], where -1 is for very negative sentiment, +1 is for very positive sentiment, and 0 is for neutral sentiment. The subjectivity is a float within the range [0, 1], where 0 is very objective and 1 is very subjective.

vaderSentiment assigns to the given text three sentiment proportions (positive, negative and neutral) whose scores sum to 1. It also calculates a compound score that is a float in [-1, 1], similar to TextBlob's polarity.

Value

Data frame. All indicators produced by TextBlob (polarity and subjectivity) and vaderSentiment (positive, negative and neutral sentiments, and compound score).

Examples

1
2
3
4
5
6
sentiments <- pxtextmineR::text_data %>%
  dplyr::select(feedback) %>%
  pxtextmineR::sentiment_scores_r()

head(sentiments)
apply(sentiments, 2, range)

nhs-r-community/pxtextmineR documentation built on Dec. 22, 2021, 2:10 a.m.