Skip to content
Prev 200060 / 398506 Next

Dist function

On Nov 12, 2009, at 1:32 PM, David Winsemius wrote:

            
If you are having problems understanding the dist help page. then  
perhaps you can think of the binary distance as the Boolean sum of  
XOR() divided by the sum of OR():

 > sum( xor(c(1,0,1,0), c(1,1,1,0))+0) / sum( c(1,0,1,0) |  
c(1,1,1,0)+0 )
[1] 0.3333333

Or using the example on the help page:

 > x <- c(0, 0, 1, 1, 1, 1)
 > y <- c(1, 0, 1, 1, 0, 1)
 > dist(rbind(x,y), method= "binary")
     x
y 0.4
 > ## answer 0.4 = 2/5

 > sum(xor(x, y)+0)/sum(x | y +0)
[1] 0.4