Skip to content

Instantly share code, notes, and snippets.

@samuel-bohman
Last active Oct 4, 2017
Embed
What would you like to do?
Function for calculating the Jaccard similarity and distance coefficients
jaccard <- function(x, m) {
if (m == 1 | m == 2) {
M_00 <- apply(x, m, sum) == 0
M_11 <- apply(x, m, sum) == 2
if (m == 1) {
x <- x[!M_00, ]
JSim <- sum(M_11) / nrow(x)
} else {
x <- x[, !M_00]
JSim <- sum(M_11) / length(x)
}
JDist <- 1 - JSim
return(c(JSim = JSim, JDist = JDist))
} else break
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment