Q:

How to calculate pairwise distances of nominal variable?

I have the following data frame where I need to calculate pairwise differences between all rows(names here).
names<- c("t1","t2","t3","t4","t5","t6","t7","t8")
v1 <- c(2,3,4,2,2,4,7,12)
v2 <- c(15,12,2,2,3,1,7,12) 
v3<- c(2,3,2,16,14,11,2,7)
v4<- c(12,3,4,5,9,1,12,13)

mydf<- data.frame(names,v1,v2,v3,v4)

So the expected output needs to be something similar to what dist(mydf[-1]) gives but those numbers are nominal characters and the order of values also matter. 
e.g: "t1 and "t2" are 4/4 different while "t1" & "t3" difference is 3/4.
Thanks

A:

What about:
ans <- expand.grid(first=1:nrow(mydf), second=1:nrow(mydf))

ans$diff <- apply(ans, 1, function(x) {
    ncols <- ncol(mydf)-1
    sum(mydf[x[1],-1] != mydf[x[2],-1]) / ncols
})

m <- matrix(ans$diff, nrow = nrow(mydf))
colnames(m) <- rownames(m) <- names
m

