gpt4 book ai didi

r - agrep 的问题

转载 作者:行者123 更新时间:2023-12-04 05:31:01 24 4
gpt4 key购买 nike

尽管我将 max.distance 限制为零,为什么 agrep 会找到匹配项?
adist 确实正确地告诉我,我需要两次插入...

> agrep("ab", "abcd", max = list(del = 0, ins = 0, sub = 0), value = T)
[1] "abcd"
> drop(attr(adist("ab", "abcd", counts = TRUE), "counts"))
ins del sub
2 0 0

> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=German_Austria.1252 LC_CTYPE=German_Austria.1252
[3] LC_MONETARY=German_Austria.1252 LC_NUMERIC=C
[5] LC_TIME=German_Austria.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] formatR_0.6 vegan_2.0-4 permute_0.7-0

loaded via a namespace (and not attached):
[1] grid_2.15.1 lattice_0.20-6 tools_2.15.1

最佳答案

请注意,“ab”与“abcd”的前两个字符完美匹配(不需要插入!)。这就是@joran 引用的 Note 部分告诉你的。

# Since ab matches the substring of abcd that is the first two characters
# we get a match
agrep("ab", "abcd", val = T)
#[1] "abcd"

# Since we only need 1 insertion to make ac into abc and we set max=1
# we get a match
agrep("ac", "abcd", max = 1, val = T)
#[1] "abcd"

# ac doesn't directly match any part of the substring and we set max=0
# so no match
agrep("ac", "abcd", max = 0, val = T)
#character(0)

关于r - agrep 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12629467/

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