If both x and y are vectors, hamming.distance returns the Hamming distance (number of different elements) between this two vectors. If x is a matrix, the Hamming distances between the rows of x are computed and y is ignored.

hamming.distance(x, y)

Arguments

x

a vector or matrix.

y

an optional vector.

Examples

x <- c(1, 0, 0) y <- c(1, 0, 1) hamming.distance(x, y)
#> [1] 1
z <- rbind(x,y) rownames(z) <- c("Fred", "Tom") hamming.distance(z)
#> Fred Tom #> Fred 0 1 #> Tom 1 0
hamming.distance(1:3, 3:1)
#> [1] 2