<p>Hmmm. Somebody is interested in exactly same thing which I have been working on.</p>

<p>Below is my code in python.</p>

<pre><code>from collections import OrderedDict


def invert(u):
    identity = sorted(u)
    ui = []
    for x in identity:
        index = u.index(x)
        ui.append(identity[index])
    print "Given U is:\n",u
    print "Inverse of U is:\n",ui
    return identity,ui

def r_vector(x,y,id):
    # from collections import OrderedDict
    id_x_Map = OrderedDict(zip(id,x))
    id_y_Map = OrderedDict(zip(id,y))
    r = []
    for x_index,x_value in id_x_Map.items():
        for y_index,y_value in id_y_Map.items():
            if (x_value == y_index):
                r.append(y_value)

    print r
    return r

def xr_vector(x):
    # from collections import OrderedDict
    values_checked = []
    unorderd_xr = []
    ordered_xr = []

    for value in x:
        values_to_right = []
        for n in x[x.index(value)+1:]:
                    values_to_right.append(n)
            result = [i for i in values_to_right if i &lt; value]
            if(len(result)!=0):
                values_checked.append(value)
                unorderd_xr.append(len(result))

    value_ltValuePair = OrderedDict(zip(values_checked,unorderd_xr))

    for key in sorted(value_ltValuePair):
        # print key,value_ltValuePair[key]
        ordered_xr.append(value_ltValuePair[key])
    print "Xr= ",ordered_xr
    print "Kendal Tau distance = ",sum(ordered_xr)



if __name__ == '__main__':
    print "***********************************************************"
    print "Enter the first string (U):"
    u = raw_input().split() 
    print "Enter the second string (V):"
    v = raw_input().split()
    print "***********************************************************"

    print "Step 1: Find U Inverse"
    identity,uinverse = invert(u)
    print "***********************************************************"

    print "Step 2: Find R = V.UInverse"
    r = r_vector(v,uinverse,identity)
    print "***********************************************************"

    print "Step 3: Finding XR and Kenday_Tau"
    xr_vector(r)
</code></pre>

<p>About the approach/ algorithm to find Kendall Tau distance this way, I would either leave it to you, or point towards the research paper <strong><a href="http://arxiv.org/pdf/1408.4963v1" rel="nofollow">Optimal Permutation Codes and the Kendall’s τ-Metric</strong></a></p>

<p>You can implement (Approach) the same in R.</p>
Kendall tau distance (a.k.a bubble-sort distance) between permutations in base R
<p>How can the Kendall tau distance (a.k.a. bubble-sort distance) between two permutations be calculated in R without loading additional libraries?</p>