Search code examples
rdplyrinner-join

R piped inner join not working


Can someone explain why this join isnt working? I am adapting code from here

library(dplyr)
library(stringr)
library(tidytext)

res<-"Hi my name"%>%strsplit("[[:space:]]")%>%inner_join(get_sentiments("afinn"))

I expected to get the intersection of these two lists. What did I do wrong? Note that get_sentiments() returns a list of words of which will have matches for "Hi", "my", "name"


Solution

  • Try this

    "Hi my name is good" %>% 
      str_split("[[:space:]]") %>% 
      unlist() %>% 
      data.frame(word = .,stringsAsFactors = F) %>% 
      inner_join(get_sentiments("afinn"),by = c("word" = "word"))