Description Usage Arguments Value Examples
Calculates cosine similarity between the columns of a matrix
1 |
x |
Matrix for which cosine similarities are to be calculated. Currently, the function requires the matrix to be symmetric and free of missing values. The matrix must have named columns specifying the identity of the things across which similarity is measured. (In my application, these are fund WFICNs.) |
lower.tri.only |
Should the returned matrix include only the lower triangle of similarities? (Useful for efficient storage of large matrices, as the returned matrix of cosine similarities is symmetric.) |
Matrix of cosine similarities, with row and column names of what is being compared.
1 2 3 4 5 6 7 8 9 10 11 12 | x.same <- matrix(0.5, 2, 2)
colnames(x.same) <- c("fund1", "fund2")
rownames(x.same) <- c("stock1", "stock2")
CosSim(x.same)
x.orthogonal <- cbind(c(1, 0), c(0, 1))
colnames(x.orthogonal) <- c("fund1", "fund2")
rownames(x.orthogonal) <- c("stock1", "stock2")
CosSim(x.orthogonal)
x <- cbind(c(0.75, 0.25), c(0.25, 0.75))
colnames(x) <- c("fund1", "fund2")
rownames(x) <- c("stock1", "stock2")
CosSim(x)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.