# this function outputs a similarity matrix based on one input data matrix
# with the interpoint dissimilarities measured by Euclidean distance
SimiFunc = function(dat){
N = nrow(dat)
SimiMat = matrix(0, N, N)
for(i in 1:N) {
for(j in 1:N) {
SimiMat[i,j] = 1/norm(as.matrix(dat[i,]-dat[j,]), type="F")
SimiMat[i,i] = 1
}
}
return(SimiMat)
}
# alternatively, the following two lines do the exact same thing
# dist.vec = dist(X, method = 'euclidean')
# dist.mat <- as.matrix(dist.vec)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.