Description Usage Arguments See Also Examples
View source: R/pairwise_similarity.R
Compute cosine similarity of all pairs of items in a tidy table.
1 2 3 | pairwise_similarity(tbl, item, feature, value, ...)
pairwise_similarity_(tbl, item, feature, value, ...)
|
tbl |
Table |
item |
Item to compare; will end up in |
feature |
Column describing the feature that links one item to others |
value |
Value |
... |
Extra arguments passed on to |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | library(janeaustenr)
library(dplyr)
library(tidytext)
# Comparing Jane Austen novels
austen_words <- austen_books() %>%
unnest_tokens(word, text) %>%
anti_join(stop_words, by = "word") %>%
count(book, word) %>%
ungroup()
# closest books to each other
closest <- austen_words %>%
pairwise_similarity(book, word, n) %>%
arrange(desc(similarity))
closest
closest %>%
filter(item1 == "Emma")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.