gpt4 book ai didi

R: agrep 结果量词

转载 作者:行者123 更新时间:2023-12-04 10:13:43 24 4
gpt4 key购买 nike

是否有内置方法来量化 agrep 的结果?功能?例如。在

agrep("test", c("tesr", "teqr", "toar"), max = 2, v=T)
[1] "tesr" "teqr"
tesr距离 test 仅 1 个字符排列, 而 teqr是 2,并且 toar是 3,因此未找到。显然, tesr具有比 teqr 更高的“概率” .如何以排列数或百分比检索它?
谢谢!

编辑:抱歉没有把这个问题放在首位。我已经在运行一个两步程序: agrep获取我的列表,然后 adist得到N个排列。 adist速度较慢,运行时间是我数据集中的一个重要因素

最佳答案

使用 adist() 的另一种选择:

s <- c("tesr", "teqr", "toar")
s[adist("test", s) < 3]

或使用 stringdist
library(stringdist)
s[stringdist("test", s, method = "lv") < 3]

这使:
#[1] "tesr" "teqr"

基准
x <- rep(s, 10e5)
library(microbenchmark)
mbm <- microbenchmark(
levenshteinDist = x[which(levenshteinDist("test", x) < 3)],
adist = x[adist("test", x) < 3],
stringdist = x[stringdist("test", x, method = "lv") < 3],
times = 10
)

这使:
enter image description here
Unit: milliseconds
expr min lq mean median uq max neval cld
levenshteinDist 840.7897 1255.1183 1406.8887 1398.4502 1510.5398 1960.4730 10 b
adist 2760.7677 2905.5958 2993.9021 2986.1997 3038.7692 3472.7767 10 c
stringdist 145.8252 155.3228 210.4206 174.5924 294.8686 355.1552 10 a

关于R: agrep 结果量词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33348437/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com