| name | stringdist |
| description | R stringdist package for string distance. Use for approximate string matching and distance metrics. |
stringdist
Approximate string matching and string distance functions.
String Distance
library(stringdist)
stringdist("hello", "hallo")
stringdist(c("hello", "world"), c("hallo", "word"))
Distance Methods
stringdist("hello", "hallo", method = "lv")
stringdist("hello", "hallo", method = "osa")
stringdist("hello", "hallo", method = "dl")
stringdist("hello", "hallo", method = "lcs")
stringdist("hello", "hallo", method = "qgram", q = 2)
stringdist("hello", "hallo", method = "cosine", q = 2)
stringdist("hello", "hallo", method = "jaccard", q = 2)
stringdist("hello", "hallo", method = "jw")
stringdist("hello", "hallo", method = "jw", p = 0.1)
stringdist("hello", "hallo", method = "soundex")
Distance Matrix
strings <- c("hello", "hallo", "hullo", "world")
stringdistmatrix(strings)
stringdistmatrix(c("hello", "world"), c("hallo", "word"))
Approximate Matching
amatch("hello", c("hallo", "world", "help"), maxDist = 2)
ain("hello", c("hallo", "world", "help"), maxDist = 2)
String Grouping
strings <- c("hello", "hallo", "hullo", "world", "word")
stringdist_grouping <- function(x, maxDist = 2) {
d <- stringdistmatrix(x)
hc <- hclust(as.dist(d))
cutree(hc, h = maxDist)
}
Phonetic Coding
phonetic("hello", method = "soundex")
phonetic("hello", method = "metaphone")
Q-grams
qgrams("hello", q = 2)
qgrams(c("hello", "world"), q = 2)
Sequence Alignment
seq_dist("hello", "hallo", method = "lv")
seq_distmatrix(c("hello", "world"), c("hallo", "word"))