find_nn | R Documentation |
find_nn
finds the nearest neighbor for a given vector. Neighbors can be found via pearson correlation, cosine similarity, Euclidean distance, or
Manhattan distance.
find_nn(vec, neighbors, n = 5, method = "cor")
vec |
The vector for which neighbors are to be found. This is either a vector saved as object or a row of the |
neighbors |
The potential neighbors, usually given as data frame or matrix. |
n |
The number of neighbors wanted as output. Defaults to |
method |
The measure used to determine the nearest neighbors. Either |
D. Schmitz
### a vector saved as object & a matrix of neighbors vector <- runif(50, 0, 10) data("gdsm_mat") find_nn(vec = vector, neighbors = gdsm_mat, 3, "cor") find_nn(vec = vector, neighbors = gdsm_mat, 3, "cosim") find_nn(vec = vector, neighbors = gdsm_mat, 3, "euclid") find_nn(vec = vector, neighbors = gdsm_mat, 3, "manhat") ### a vector specified by its name & its matrix of neighbors data("gdsm_mat") find_nn(vec = "var12", neighbors = gdsm_mat, 3, "cor") find_nn(vec = "var12", neighbors = gdsm_mat, 3, "cosim") find_nn(vec = "var12", neighbors = gdsm_mat, 3, "euclid") find_nn(vec = "var12", neighbors = gdsm_mat, 3, "manhat")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.