Search code examples
rtext-miningsentiment-analysis

Inner Join not working for R sentiment analysis


I'm trying to conduct sentiment analysis on a Simpsons' episode using the afinn library but for some reason when I inner join sentiment with my tidy_text and filter for words labelled -5, it returns words in the afinn library that are not in my dataframe.

I double checked my df ('tidy_text') and it definitely is a subset of words from the episode.

Any idea what I'm doing wrong here?

afinn <- tidy_text %>%
  inner_join(get_sentiments("afinn")) %>%
  filter(value == -5) %>%
  count(word, value, sort = TRUE)



Solution

  • Sounds like an interesting project. Try adding , by = c("word" = "word")) %>%

    afinn <- tidy_text %>%
      inner_join(get_sentiments("afinn"), by = c("word" = "word")) %>%
      filter(value == -5) %>%
      count(word, value, sort = TRUE)