R/utils.R
hamming_dist.Rd
The Hamming distance of two vectors corresponds to the number of positions where the values differ.
hamming_dist(x, y, norm = FALSE) x %HD% y x %NHD% y
A numeric or logical vector
If TRUE normalize the distance to the vector length. By default it's FALSE
TRUE
FALSE
The Hamming distance
NAs are discarded in any of the vectors by using na.rm = TRUE in sum.
na.rm = TRUE
sum
hamming_dist(c(0, 1, 0), c(0, 0, 0)) #> [1] 1 hamming_dist(c(0, 1, 0), c(0, 0, 0), norm = TRUE) #> [1] 0.3333333 ## NAs in any of the vectors are discarded hamming_dist(c(1, NA, 3, 4, 5), c(1, 2, NA, 4, 5)) #> [1] 0 c(0, 1, 0) %HD% c(1, 0, 0) #> [1] 2 c(0, 1, 0) %NHD% c(1, 0, 0) #> [1] 0.6666667