How to calculate various known similarities or measures of the distance between two vectors in R?

I want to calculate the similarity (distance) between two vectors:

v1 <- c(1, 0.5, 0, 0.1) v2 <- c(0.7, 1, 0.2, 0.1) 

I just want to know if a package is available for calculating various known similarity (distance) methods in R? For example, "Resnik", "Lin", "Rel", "Jiang", ...

The implementation of this method is not complicated, but I really think that it should be defined in some packages in R.

After some searches, I found the "GOSemSim" package, which contains most measures, but it is specific to a biomedical application, and I cannot use them to calculate the similarity between two vectors.

+6
source share
2 answers

" proxy " is a common library for measuring distance and similarity. The following methods are supported:

"Jacquard" "Kulchinsky1" "Kulchinsky2" "Mountford" "Fager" "Russell" "Simple juxtaposition" "Hamman" "Faith"
“Tanimoto” “Cubes” “Fi” “Styles” “Michael” “Moseley” “Yule” “Yule2” “Ochayay”
"Simpson" "Brown Blanket" "cosine" "eJaccard" "fJaccard" "correlation" "Chi-square" "Phi-square" "Scuba"
"Kramer" "Pearson" "Gower" "Euclid" "Mahalanobis" "Bhuttacharya" "Manhattan" "Supremum" "Minkowski"
“Canberra” “Wave” “divergence” “Kulbek” “Bray” “Soergel” “Levenshtein” “Tribute” “Accord”
"Geodesic" "Whittaker" "Hellinger"

See the following example:

 x <- c(1,2,3,4,5) y <- c(4,5,6,7,8) l <- list(x, y) simil(l, method="cosine") 

The output is a similarity matrix between the "l" elements:

  1 2 0.978232 

The only problem I am facing is that for some methods (such as: "Jaccard") the following error occurs:

 simil(l, method="Jaccard") Error in n - d : 'n' is missing 
+8
source

The dist function supports through its argument method : Euclidean, maximum, Manhattan, Canberra, binary, or Minkowski. See ?dist

+1
source

All Articles