TL;博士
- 使用模糊字符串匹配来解决拼写错误。
- 解决这些
Jennifer问题需要Alice您知道在数据库中查找这些情况的位置,或者讨论制作更好的 Excel 文件以强制人们仅输入名字(例如,对限制在给定列表的单元格进行输入)。
模糊字符串匹配
在 R 中,您可以使用adist或stringdist包。这些可用于测量从条目(例如Aalice到潜在匹配列表)的距离[Alice, Bianca, Chris]。
这是一篇解释如何使用两者的文章。
文章摘录:
source1.devices<-read.csv('[path_to_your_source1.csv]')
source2.devices<-read.csv('[path_to_your_source2.csv]')
# To make sure we are dealing with charts
source1.devices$name<-as.character(source1.devices$name)
source2.devices$name<-as.character(source2.devices$name)
# It creates a matrix with the Standard Levenshtein distance between the name fields of both sources
dist.name<-adist(source1.devices$name,source2.devices$name, partial = TRUE, ignore.case = TRUE)
# We now take the pairs with the minimum distance
min.name<-apply(dist.name, 1, min)
match.s1.s2<-NULL
for(i in 1:nrow(dist.name))
{
s2.i<-match(min.name[i],dist.name[i,])
s1.i<-i
match.s1.s2<-rbind(data.frame(s2.i=s2.i,s1.i=s1.i,s2name=source2.devices[s2.i,]$name, s1name=source1.devices[s1.i,]$name, adist=min.name[i]),match.s1.s2)
}
# and we then can have a look at the results
View(match.s1.s2)
所有这些都假设您有一个实际有效的名称列表。