R/hamming_distance.R

Defines functions hamming_distance

Documented in hamming_distance

hamming_distance <-
function(X) {
    X=as.matrix(X)
    uniqs <- unique(as.vector(X))
    U <- X == uniqs[1]
    H <- U %*% t(U)
    for ( uniq in uniqs[-1] ) {
        U <- X == uniq
        H <- H + U %*% t(U)
    }
    ncol(X) - H
}
peterwu19881230/microbialPhenotypes documentation built on March 19, 2021, 6:36 a.m.