【发布时间】:2017-01-25 10:39:12
【问题描述】:
我正在尝试使用 agrep 函数根据公司名称模糊匹配两个不同的数据框。为了改进匹配,我只想匹配位于同一国家/地区的公司。
df1: df2:
Company ISO Company ISO
Aalberts Industries NL Aalberts NL
Allison NL Allison transmission NL
Allison UK Allison transmission UK
我使用如下函数进行匹配:
testb$test <- ""
for(i in 1:dim(testb)[1]) {x2 <- agrep(testb$name[i], testa$name, ignore.case=TRUE, value=TRUE, max.distance = Inf, useBytes = TRUE, fixed = TRUE)
x2 <- paste0(x2,"")
testb$test2[i] <- x2
}
我可以为每个国家/地区创建一个子集,然后匹配每个子集,这可行,但很耗时。如果 df1$ISO = df2$ISO,是否有另一种方法让 R 只匹配公司名称?谢谢!
【问题讨论】:
标签: r text-mining fuzzy-search