R/Ldist.R

Defines functions Ldist

## Calculates  Levenshtein distance:

Ldist <- function(pattern, strings){
    minD <- function(string, pattern){ 
        for (i in seq(0, 1, .001)) {
            x <- agrep(pattern, string, max.distance = i)
            if (!identical(x, integer(0))) {
                m <- i
                break
            }
        }
        m
    }
    unlist(lapply(strings, minD, pattern = pattern))
}

Try the qdap package in your browser

Any scripts or data that you put into this service are public.

qdap documentation built on May 31, 2023, 5:20 p.m.