R sentiment analysis; 'lexicon' not found;

473 Views Asked by At

i am very new to sentiment analysis. I am running the codes based on the tutorial here

It is using a tidytext package. But I encountered the problem when I run the code

AFINN <- sentiments %>%
  filter(lexicon == "AFINN") %>%
  select(word, afinn_score = score)

AFINN

The error is as below

Error: Problem with `filter()` input `..1`.
✖ object 'lexicon' not found
ℹ Input `..1` is `lexicon == "AFINN"`.

I guess it is because the lexicon column is not in the sentiments dataframe. Or is the tidytext package changed so that i could not run the code the way that the tutorial ran it? is there any other way to correct the code or run another similar code?

Thank you in advance for your clarification.

1

There are 1 best solutions below

2
Goldsmif On

I followed the same tutorial and had to make the following change

AFINN <- sentiments %>%
  filter(lexicon == "AFINN") %>%
  select(word, afinn_score = score)

becomes

AFINN <- get_sentiments("afinn") %>%
  select(word, afinn_score = value)

Then the rest of the tutorial worked