忽略 stringdist::extract 中 maxDist 的大小写

Ignoring the case for maxDist in stringdist::extract

我在 R 中使用 stringdist 包。

几个选项:

grab(x, pattern, maxDist = Inf, value = FALSE, ...)

grabl(x, pattern, maxDist = Inf, ...)

extract(x, pattern, maxDist = Inf, ...)

它使用 maxDist。但是,此选项将 Aa 之间的距离计为一个。正如Ab之间的距离。我想忽略字母大小写,因为 maxDist。有人知道怎么做吗?

您可以使用 tolower 并以小写形式编写您的模式以忽略大小写:

x <- "Abc"
stringdist::extract(x, pattern = "abd", maxDist = 1)
#>      [,1]
#> [1,] NA
stringdist::extract(tolower(x), pattern = "abd", maxDist = 1)
#>      [,1] 
#> [1,] "abc"

reprex package (v2.0.1)

于 2021-11-04 创建