[R] 'distance' between a vector and a permutation of the vector

From: Rajarshi Guha <rguha_at_indiana.edu>
Date: Mon, 17 Mar 2008 19:25:25 -0400


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi, I've been trying to identify a good way to do the following:

Say I have a vector of unique, integers

x <- c(1,3,2,4,5)

I then have a permuted version of the above vector, say

y <- c(1,3,5,2,4)

Is there an easy way to get the "distance" between the two vectors. The sense I'm thinking of is such, that if we have

y <- c(1,3,2,5,4)

then this is 'closer' to x, since there is only one pair that is mis- ordered, compared to something like

y <- c(1,5,3,4,2)

It seems that a good candidate would be the levenstein distance - is there a function that would work on vectors of integers rather than strings? Are there more suitable candidates?

Thanks for any pointers

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkfe/eUACgkQZqGSLFHnnoSyVwCfVi8eLnXy1eCYfAwOEF2F93cJ 1BUAoPD9vTagEGNKom5hCuR8ppb0bVgZ
=hbc7
-----END PGP SIGNATURE-----



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 17 Mar 2008 - 23:33:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 18 Mar 2008 - 00:30:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive