[R] hamming distance

Carlos J. Gil Bellosta cgb at datanalytics.com
Thu Nov 24 17:25:29 CET 2005


True, but if

>     x <- c(1, 0, 0)
>     y <- c(1, 0, 1),

then you can just define

hamming.distance <- function(x,y){
  sum(x != y)
}

The problem is just a bit harder when x and y are, for instance, strings.

Carlos J. Gil Bellosta
http://www.datanalytics.com

Quoting JeeBee <JeeBee at troefpunt.nl>:

> You could install.packages("e1071")
> and see help("hamming.distance")
>
> JeeBee.
>
>
> hamming.distance            package:e1071            R Documentation
> Hamming Distances of Vectors
> Description:
>     If both 'x' and 'y' are vectors, 'hamming.distance' returns the
>     Hamming distance (number of different bytes) between this two
>     vectors. If 'x' is a matrix, the Hamming distances between the
>     rows of 'x' are computed and 'y' is ignored.
> Usage:
>      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)
>     z <- rbind(x,y)
>     rownames(z) <- c("Fred", "Tom")
>     hamming.distance(z)
>
>
> On Thu, 24 Nov 2005 11:33:45 +0100, Ana Conesa wrote:
>
>>
>>    Hi,
>>    Does anyone know an R function to impute hamming distance?
>>    Thanks
>>    Ana
>>
>>       O@@@@@  &nb     @@@O@@O@   Centro de Genómica
>>      @O@@@@O@   Instituto Valenciano de Investigaciones Agrarias (IVIA)
>>      @@@O@@@@   Carretera Moncada - Naquera, Km. 4,5
>>       @@@@O@    46113 Moncada (Valencia) SPAIN
>>         ||  &        ||  &
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! 
>> http://www.R-project.org/posting-guide.html
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list