An Integer vector can be thought of as a single string encoded in UTF-32 (in which one Unicode code point is represented as one 32-bit integer). You can get a โnormalโ string by simply converting such a vector to UTF-8 using intToUtf8 .
intToUtf8(c(65, 97)) ## [1] "Aa"
By the way, adist defaults to utf8ToInt (reverse op) by its inputs. Thus, it calculates the results by integer vectors. No big hack.
This is the solution.
adist(intToUtf8(c(1, 3, 4, 5, 6, 7, 8)), intToUtf8(c(54, 23, 12, 53, 7, 8)), counts=TRUE) ## [,1] ## [1,] 5 ## attr(,"counts") ## , , ins ## ## [,1] ## [1,] 0 ## ## , , del ## ## [,1] ## [1,] 1 ## ## , , sub ## ## [,1] ## [1,] 4 ## ## attr(,"trafos") ## [,1] ## [1,] "SSSSDMM"
The above code should work if at least all numbers are strictly greater than 0. R handles Unicode code codes rather liberally (actually, too liberal, but in this case you are a winner), even the maximum possible integer is accepted:
utf8ToInt(intToUtf8(c(2147483647)))
If you have a vector with negative values, you can somehow transform it, for example. with x <- x-min(x)+1 .
If you need different costs for inserting, deleting, replacing, check the adist's costs argument. There is also a package called stringdist that includes many other string metrics. The above scheme should also work there.