【发布时间】:2021-09-28 19:23:37
【问题描述】:
已完成连接操作以将地址与其自身进行比较。
library(tidyverse)
library(lubridate)
library(stringr)
library(stringdist)
library(fuzzyjoin)
doTheJoin <- function (threshold) {
joined <- trimData(d_client_squashed) %>%
stringdist_left_join(
trimData(d_client_squashed),
by = c(address_full="address_full"),
distance_col = "distance",
max_dist = threshold,
method = "jw"
)
}
d_client_squashed 的结构如下,包含字符串值:
| Client_Reference | adress_full |
|---|---|
| C01 | Client1 Name, Street, Zipcode, Town |
| C02 | Client2 Name, Street2, Zipcode2, Town2 |
| ... | ... |
以下操作:
sensible_matches <- doTheJoin(0.2)
View(sensible_matches %>% filter(Client_Reference.x != Client_Reference.y))
结果如下:
| Client_Reference.x | address_full.x | Client_Reference.y | address_full.y | Distance |
|---|---|---|---|---|
| C01 | Client1 Name, Street, Zipcode, Town | C02 | Client2 Name, Street2, Zipcode2, Town2 | 0.05486 |
| C02 | Client2 Name, Street2, Zipcode2, Town2 | C01 | Client1 Name, Street, Zipcode, Town | 0.05486 |
| ... | ... | ... | ... | ... |
此连接操作的输出是双重的,带有反向的客户端信息。距离值不是唯一的。如何对数据框进行子集化以避免那些双线?
【问题讨论】:
-
你想要的输出是什么?你已经过滤了
(Client_Reference.x != Client_Reference.y),所以你的样本是我所期望的。 `(Client_Reference.x == Client_Reference.y) 能给你想要的吗? -
总体目标是获取一个包含相似地址的列表,以便识别存在拼写错误或差异的重复条目,例如“Bachstr. 5”和“Bach Street 5”应该是相同的。使用 (Client_Reference.x != Client_Reference.y) 我想避免自己比较客户端地址。请求操作的目标是摆脱具有相同距离值但 Client_Reference.x 和 Client_Reference.y 只是倒置的第二行。因此,我想从列表中删除它的双重结果,以免对其进行两次验证。
-
给每一行一个 rownumber .. 然后只在 rownumer.i > rownumber.j .. 的夫妇 (i,j) 上工作
-
怎么样
Client_Reference.x > Client_Reference.y而不是Client_Reference.x != Client_Reference.y -
@Waldi 我真的很喜欢这种尝试。不幸的是,该解决方案无法在 Client_Reference.x 和 .y 上应用比较,因为这些都是因素。