cosdist | R Documentation |
Calculate the cosine distance between two vectors (matrices)
cosdist(x, y, na.rm = TRUE)
x |
An integer or numeric vector or matrix |
y |
An integer or numeric vector or matrix |
na.rm |
Logical, whether |
Cossine distance is defined by 1-cossim, where cossim represents the cosine similarity.
If parameters are given as matrices, the function calculates the cossine distance between all pair of columns of both matrices.
Numeric vector or matrix, the cossine similarity between the inputs
Currently, na.rm
is only considered when both inputs are vectors
Jitao David Zhang <jitao_david.zhang@roche.com>
http://en.wikipedia.org/wiki/Cosine_similarity
cor
, cossim
testVal1 <- rnorm(10) testVal2 <- rnorm(10) testVal3 <- c(rnorm(9), NA) cosdist(testVal1, testVal2) cosdist(testVal1, testVal3, na.rm=TRUE) cosdist(testVal1, testVal3, na.rm=FALSE) ## test matrix testMat1 <- matrix(rnorm(1000), nrow=10) testMat2 <- matrix(rnorm(1000), nrow=10) testVecMatDist1 <- cosdist(testMat1[,1L], testMat2) testVecMatDist <- cosdist(testMat1, testMat2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.