我的数据包括一个名称列。一些名称以多达八种不同的方式书写。我尝试使用以下代码对它们进行分组:
groups <- list()
i <- 1
while(length(x) > 0)
{
id <- agrep(x[1], x, ignore.case = TRUE, max.distance = 0.1)
groups[[i]] <- x[id]
x <- x[-id]
i <- i + 1
}
head(groups)
groups
接下来,我想添加一个新列,该列返回例如最常用的每行名称表示法。结果应如下所示:
A B
1. John Snow John Snow
2. Peter Wright Peter Wright
3. john snow John Snow
4. John snow John Snow
5. Peter wright Peter Wright
6. J. Snow John Snow
7. John Snow John Snow
etc.
我如何到那里?