# samples 1 and 2, and 3 and 4, have no species in common
x <- matrix(c( 1, 0, 1, 0,
0, 1, 0, 1,
1, 0, 0, 0,
0, 1, 1, 1,
1, 1, 1, 0,
1, 0, 1, 1,
0, 0, 1, 1), ncol = 4, byrow = TRUE)
# the maximum Jaccard distance is 1
# regardless of how different the samples are
x.jd <- dist(x, "binary")
# estimate the true distance between those pairs
# by following the shorted path along connected sites
pathdist(x.jd)
Run the code above in your browser using DataLab