What's the Kendall Tau's distance between these 2 rankings? ranking i: {3, 1, 2}
ranking j: {2, 1, 3}
I am referring to the Wikipedia page here, and to calculate the Kendall distance, I just need to count the number of times the values in ranking i are in the opposite order of the values in ranking j. 
3 < 1 in ranking i, but 3 > 1 in ranking j
3 < 2 in ranking i, but 3 > 2 in ranking j
1 < 2 in ranking i, but 1 > 2 in ranking j
There are 3 switches, so the Kendall distance is 3. However when I call a function to calculate the Kendall's distance in R, it returns 1. What's the correct Kendall's distance between these 2 rankings? 
 A: The wrong answer got accepted!  The correct answer is 3.
From Wikipedia:
Kendall tau distance is also called bubble-sort distance since it is equivalent to the number of swaps that the bubble sort algorithm would take to place one list in the same order as the other list.
import itertools

def kendall_tau_distance(order_a, order_b):
    pairs = itertools.combinations(range(1, len(order_a)+1), 2)
    distance = 0
    for x, y in pairs:
        a = order_a.index(x) - order_a.index(y)
        b = order_b.index(x) - order_b.index(y)
        if a * b < 0:
            distance += 1
    return distance

print kendall_tau_distance([3,1,2], [2,1,3])
3

A: The Kendall tau distance in your case is, indeed, 1.
See the following python code:
import itertools

def kendallTau(A, B):
    pairs = itertools.combinations(range(0, len(A)), 2)

    distance = 0

    for x, y in pairs:
        a = A[x] - A[y]
        b = B[x] - B[y]

        # if discordant (different signs)
        if (a * b < 0):
            distance += 1

    return distance


ranking_i = [3, 1, 2]
ranking_j = [2, 1, 3]
assert kendallTau(ranking_i, ranking_j) == 1

A: The Kendall tau distance in this instance is 3. It is also known as Kemeny distance. See here and here.
In some fields rankings are also allowed to have ties, therefore the Kemeny could be considered as a distance of 6 instead of 3. That's a confusion that arises quite often. But in your situation it is 3 because ties are not allowed. 
A: Kendell tau distance is the number of swaps which needs to be done for making the two lists the same. It can also be considered as a variant of Insertion Sort, where each swap adds +1 to Kendell distance.
