【发布时间】:2015-10-04 18:48:24
【问题描述】:
我有一个模式向量,需要在它们上使用agrep。问题是agrep 似乎一次只采用一种模式。
patt <- c("test","10 Barrel")
lut <- c("1 Barrel","10 Barrel Brewing","Harpoon 100 Barrel Series","resr","rest","tesr")
for (i in 1:length(patt)) {
print(agrep(patt[i],lut,max=1,v=T))
}
结果:
[1] "rest" "tesr"
[1] "1 Barrel" "10 Barrel Brewing" "Harpoon 100 Barrel Series"
for 在长模式上很慢,因此尝试以矢量化形式进行:
VecMatch1 = function(string, stringVector){
stringVector[agrep(string, stringVector, max = 1)]
}
a = VecMatch1(patt,lut)
Warning message:
In agrep(string, stringVector, max = 1) :
argument 'pattern' has length > 1 and only the first element will be used
lapply 等函数可能有帮助吗?谢谢!!
【问题讨论】:
标签: r fuzzy-search agrep