For example, I have a line of text "i appreciate the help" I want to remove the word "appreciate" from the sentimentr dictionary, so that it will not factor to any sentiment score moving forward.

1

There are 1 best solutions below

0
On

You can create your own sentiment table. Either from scratch or from using the default one.

Example:

library(sentimentr)

txt <- "i appreciate the help"
sentiment(txt)
   element_id sentence_id word_count sentiment
1:          1           1          4      0.25

Adjust the sentiment table. Since the sentiment tables are stored as data.tables first load data.table.

library(data.table)

# remove word we do not want from default sentiment table coming from lexicon package
my_sent_table <- lexicon::hash_sentiment_jockers_rinker[x != "appreciate"]

sentiment(txt, polarity_dt =  my_sent_table)
   element_id sentence_id word_count sentiment
1:          1           1          4         0