Good question. Thank you so clearly formulated the question. I am currently working on clustering and have parked this issue for resolution later.
Here is a graphical way to solve the problem.
library(ggplot2) # Create dummy data # In the first instance, there is perfect transposition between A and D d <- data.frame( clust1 = LETTERS[rep(1:4, 3)], clust2 = LETTERS[rep(c(4,1,2,3), 3)] ) ggplot(d, aes(x=clust1, y=clust2)) + geom_point(stat="sum", aes(size=..n..))

# Now modify data so that there is a single instance of imperfect matching d$clust2[1] <- "A" ggplot(d, aes(x=clust1, y=clust2)) + geom_point(stat="sum", aes(size=..n..))

source share