基于agrep的双矢量R模糊匹配
我想使用模糊匹配比较人们访问过的地方的两个向量,我正在使用agrep基于agrep的双矢量R模糊匹配,r,R,我想使用模糊匹配比较人们访问过的地方的两个向量,我正在使用agrep person1<-c("supermarket","garage","garden centre","restaurant") person2<-c("supermkt","park","gdn center","gym","italian res
person1<-c("supermarket","garage","garden centre","restaurant")
person2<-c("supermkt","park","gdn center","gym","italian restaurant")
我想要的是一种方法来迭代person 1访问过的地方,以得出结果“3”,并将其分配给变量eg
person1result不确定我是否正确理解您的问题。但迭代的一种方法是使用for循环
或等效的*apply
函数,如下所示:
sapply(person1, function(x)agrep(x, person2, max.distance = 0.3))
[1] 1 3 5
从这里,我希望您可以继续解决问题的剩余部分。这里有一个选项,使用outer
+agrepl
which(
outer(
person1,
person2,
FUN = Vectorize(function(x, y) agrepl(x, y, max.distance = 0.3))
),
arr.ind = TRUE
)[, "col"]
给
[1] 1 3 5
[1] 1 3 5