I modified code from Dr. Silge's Text Mining book, but chose to use weighted log odds instead of term frequency inverse document frequency due to this blog post (3.2 Weighted log odds ratio | Notes for “Text Mining with R: A Tidy Approach”). My code is below, but this is resulting in 2 values for the same term; if I want one value per term and the term assigned to the group that it is most likely to be in, how would I accomplish this?
words_by_weapon <- text_clean_words %>%
add_count(weapon, name = "total_words") %>%
group_by(weapon, total_words) %>%
count(word, sort = TRUE) %>%
filter(!word %in% stop_words$word)
wlo_all <- words_by_weapon %>%
bind_log_odds(set = weapon, feature = word, n = n)