cosSim | R Documentation |
Calculate cosine similarity between two vectors of the same length, or cosine similarity between two matrices
cosSim(x, ...)
## Default S3 method:
cosSim(x, y)
## S3 method for class 'matrix'
cosSim(x, y, all.vs.all = FALSE, by.row = TRUE)
## S3 method for class 'data.frame'
cosSim(...)
x |
A numeric vector or matrix |
y |
A numeric vector or matrix |
all.vs.all |
(When x and y are matrices) If TRUE, all rows of x are compared with all rows of y. If FALSE, rows of x are compared with rows of y 'side-by-side' |
by.row |
(When x and y are matrices) If TRUE, compare rows. If FALSE, compare columns |
A numeric vector or matrix
set.seed(1)
x <- matrix(runif(200), nrow=20)
y <- matrix(runif(200), nrow=20)
## Works with matrices
cosSim(x, y)
## ...or vectors
cosSim(x[1,], y[1,])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.