当您agrep
与value = FALSE
结果一起使用时,“一个向量给出了产生匹配的元素的索引”。也就是说,匹配在您输入的名称向量中的位置agrep
。然后,您尝试用较短的索引向量(其中 3074 行)替换数据框中的整个name变量(67424 行)。不是你想要的。这是一个小例子,也许可以指导您朝着正确的方向前进。你也可以阅读和这个。本身的细节(例如),我留给你。?Extract
agrep
max.distance
# create a data frame with some MC DONALD's-ish names, and some other names.
rest2012 <- data.frame(CONAME = c("MC DONALD'S", "MCC DONALD'S", "SPSS Café", "GLM RONALDO'S", "MCMCglmm"))
rest2012
# do some fuzzy matching with 'agrep'
# store the indices in an object named 'idx'
idx <- agrep(pattern = "MC DONALD'S", x = rest2012$CONAME, ignore.case = FALSE, value = FALSE, max.distance = 3)
idx
# just look at the rows in the data frame that matched
# indexing with a numeric vector
rest2012[idx, ]
# replace the elements that matches
rest2012[idx, ] <- "MC DONALD'S"
rest2012