Filter the output so that bigram chart must contain specific words

41 Views Asked by At

I am having issues filtering my bigram so that it contains a specific word in it. Here is the code:

    light_df$text %>%
  unnest_tokens(word, text, token = "ngrams", n = 2) %>%
  separate(word, c("word1", "word2"), sep = " ") %>%
  filter(!word1 %in% stop_words$word) %>%
  filter(!word2 %in% stop_words$word) %>%
  unite(word, word1, word2, sep = " ") %>%
  filter(word1 == "light" | word2 == "light") %>%
  count(word, sort = TRUE) %>%
  slice_max(n, n = 25) %>%
  ggplot() +
  geom_bar(aes(word, n), stat = "identity", fill = "#de5833") +
  theme_minimal() +
  coord_flip()

When I did it before adding the filter, it worked perfectly. Then I only added the filter function but when i run it, this error appears:

Error in filter(., word1 == "light" | word2 == "light") : Caused by error: ! object 'word1' not found

Where is the mistake?

0

There are 0 best solutions below