View source: R/calculate_similarity.R
calculate_similarity | R Documentation |
This function uses the 'lsa' package to calculate the 'cos' between vectors. For this function, you should have a matrix of tokens by dimensions, and you can specify which direction you want to calculate the cosine (by rows or columns).
calculate_similarity(words = NULL, dimensions, by = 1)
words |
If you want to filter the matrix to only a set of tokens, include a vector of tokens. The 'by' argument will be used to filter the data to only these values. Note that if you want to filter by rows, the row names should represent your tokens, not the first column. |
dimensions |
Your matrix of numerical dimension values. |
by |
use '1' to calculate by row and '2' to calculate by column. |
A matrix of cosine values between either rows or columns.
# af_cosine <- calculate_similarity(
# words = af_final$sentence, # the tokens you want to filter
# dimensions = af_dims, # the matrix of items
# by = 1 # 1 for rows, 2 for columns)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.