R/hamming.distance.R

Defines functions hamming.distance

Documented in hamming.distance

hamming.distance <- function(x,y){

  z<-NULL

  if(is.vector(x) && is.vector(y)){
    z <- sum(x != y)
  }
  else{
    z <- matrix(0,nrow=nrow(x),ncol=nrow(x))
    for(k in 1:(nrow(x)-1)){
      for(l in (k+1):nrow(x)){
	z[k,l] <- hamming.distance(x[k,], x[l,])
	z[l,k] <- z[k,l]
      }
    }
    dimnames(z) <- list(dimnames(x)[[1]], dimnames(x)[[1]])
  }
  z
}

Try the e1071 package in your browser

Any scripts or data that you put into this service are public.

e1071 documentation built on Feb. 16, 2023, 8:31 p.m.