Given two permutations:
v1
[1] 4 3 1 5 2
v2
[1] 2 3 4 5 1
How do you compute the Spearman's footrule distance (total displacement of all elements) with base R? (flexible for any two permutations of size n
)
For example, for these two vectors, it's as follows:
1
is moved 2
places from v1
to v2
2
is moved 4
places from v1
to v2
3
is moved 0
places from v1
to v2
4
is moved 2
places from v1
to v2
5
is moved 0
places from v1
to v2
So the total distance would be: 2+4+0+2+0 = 8