1

I would like to use R to compare a lot of integer lists, using edit-distance. Ex: list1[231, 3883, 21099, 12, 2] and list2[433, 3883, 12, 919, 2]

I'd like to get just the distance between those two list. Ex. with the lists above, the distance would equal 3. Because to make list2 like list1, you would substitute 231 for 433, then add 21099 after 3883, then delete 919.

I would like to find how many adds and removes I would need to make list1 look like list2. I know that R has the built in function: adist(). That however, only seems to work for comparing strings (not even lists of strings). Google keeps pushing me to adist() and dist() neither of which are going to solve this problem. I'd rather not reinvent the wheel, so is there a function already in existence? I've attempted to rewrite adist() as found here: https://searchcode.com/codesearch/view/13555814/ but its too complex for my current R ability.

  • `adist(list1,list2)` works fine if you make your data vectors, e.g: - `list1 <- c(231,3883,21099,12,2)` It converts numbers to strings automatically. – thelatemail Jul 13 '15 at 22:08
  • That seems to calculate the distance between each individual point and dump the result to a matrix. Ex `list1 <- c(101, 4333)` and `list2 <- (32, 101)` then `adist(list1, list2)` outputs: `row1: 3, 0` `row2: 3, 4` I'll add a better explanation of what I'm looking for above. – TheNoviceAllen Jul 13 '15 at 22:50
  • That's a more interesting question then - I'm not sure off the top of my head how that would work. – thelatemail Jul 13 '15 at 23:19
  • 3
    See if [this answer](http://stackoverflow.com/questions/23674038/levenshtein-type-algorithm-with-numeric-vectors) is whaty ou were after? – mathematical.coffee Jul 13 '15 at 23:19

0 Answers0