- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 R 中使用“agrep”函数,它返回匹配向量。我想要一个类似于 agrep 的函数,它只返回最佳匹配,或者如果存在平局则返回最佳匹配。目前,我正在对结果向量的每个元素使用“cba”包中的“sdist()”函数来执行此操作,但这似乎非常多余。
/edit:这是我当前正在使用的功能。我想加快速度,因为计算两次距离似乎是多余的。
library(cba)
word <- 'test'
words <- c('Teest','teeeest','New York City','yeast','text','Test')
ClosestMatch <- function(string,StringVector) {
matches <- agrep(string,StringVector,value=TRUE)
distance <- sdists(string,matches,method = "ow",weight = c(1, 0, 2))
matches <- data.frame(matches,as.numeric(distance))
matches <- subset(matches,distance==min(distance))
as.character(matches$matches)
}
ClosestMatch(word,words)
最佳答案
agrep 包使用 Levenshtein Distances 来匹配字符串。 RecordLinkage 包有一个 C 函数来计算 Levenshtein 距离,可以直接使用它来加速计算。这是一个重新设计的 ClosestMatch
函数,速度提高了大约 10 倍
library(RecordLinkage)
ClosestMatch2 = function(string, stringVector){
distance = levenshteinSim(string, stringVector);
stringVector[distance == max(distance)]
}
关于r - agrep:只返回最佳匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5721883/
是否有内置方法来量化 agrep 的结果?功能?例如。在 agrep("test", c("tesr", "teqr", "toar"), max = 2, v=T) [1] "tesr" "teqr
尽管我将 max.distance 限制为零,为什么 agrep 会找到匹配项? adist 确实正确地告诉我,我需要两次插入... > agrep("ab", "abcd", max = list(
我在 R 中使用“agrep”函数,它返回匹配向量。我想要一个类似于 agrep 的函数,它只返回最佳匹配,或者如果存在平局则返回最佳匹配。目前,我正在对结果向量的每个元素使用“cba”包中的“sdi
我有一个模式向量,需要对它们使用 agrep。问题是 agrep 似乎一次只采用一种模式。 patt 1 and only the first element will be used lapply
我的目标是确定是否给定 text有一个 target字符串,但我想允许拼写错误/小派生并提取“导致”匹配的子字符串(将其用于进一步的文本分析)。 示例: target <- "target strin
在?agrep(带有模糊匹配的grep)中,它提到我可以设置参数fixed=FALSE来解释我的模式作为正则表达式。 但是,我无法让它工作! agrep('(asdf|fdsa)', 'asdf',
我正在尝试做的是使用 agrep 获取文件中最匹配的词和它的错误数。现在我只能使用这个脚本来获取单词: array=(bla1 bla2 bla3) for eachWord in "${array[
我是一个 R 新手,一直在尝试使用 agrep 进行一些实验。 R 中的函数。我有一个庞大的客户数据库(150 万行),我确信其中有很多重复项。尽管使用 table() 来获取重复确切名称的频率,但并
我需要一些帮助来理解这些函数的参数。我从帮助中拿了例子。 ## To see the transformation counts for the Levenshtein distance: drop(
我正在尝试从 data.frame 转换至 data.table ,并且需要一些关于我正在尝试在单个列上执行的逻辑索引的建议。这是我有的一张表: places <- data.table(name=c
使用 R,我尝试匹配按年份和城市构建的数据集中的人名。由于一些拼写错误,无法精确匹配,因此我尝试使用 agrep() 来模糊匹配名称。 数据集的示例 block 的结构如下: df <- data.f
我有一个字符串: string <- "I do not like green eggs and ham!" 和一个图案 pattern <- "(egs|ham)" 我想知道多少次pattern匹配
我的Java程序需要启动agrep.exe,其参数包含大矩阵中所有元素对的参数,并获取两个字符串的匹配错误数。我写了一段代码,但是运行速度很慢。我可以加快这部分代码的速度吗?或者,也许你可以建议我一些
我正在尝试使用 agrep 找出两个字符串名称之间模糊字符串匹配的最佳精度。 但是,由于字符串数量巨大,我需要选择一个精度“max.distance”以将其应用于我尝试匹配的所有字符串。不可能为我尝试
编辑:这个错误是在 32 位版本的 R 中发现的,已在 R 版本 2.9.2 中得到修复。 这是@leoniedu 今天发给我的推特,我没有他的答案,所以我想我会把它贴在这里。 我已经阅读了 agre
我是一名优秀的程序员,十分优秀!