Skip to content

Instantly share code, notes, and snippets.

@deldersveld
Last active September 23, 2016 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deldersveld/5386bb905d89c9264349745cea50dcd1 to your computer and use it in GitHub Desktop.
Save deldersveld/5386bb905d89c9264349745cea50dcd1 to your computer and use it in GitHub Desktop.
R script that compares sentence/phrase sentiment using various lexicons from the Syuzhet package. Script is geared toward Microsoft Power BI with the "dataset" data frame, but it can easily be adapted for any data frame.
bing.sentiment <- syuzhet::get_sentiment(as.vector(dataset$Text), method="bing")
afinn.sentiment <- syuzhet::get_sentiment(as.vector(dataset$Text), method="afinn")
nrc.sentiment <- syuzhet::get_sentiment(as.vector(dataset$Text), method="nrc")
raw <- cbind(bing.sentiment, afinn.sentiment, nrc.sentiment)
scaled <- scale(raw, center=TRUE)
colnames(scaled) <- c("bing.scaled", "afinn.scaled", "nrc.scaled")
sentiment.output <- cbind(dataset, raw, scaled)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment