如何从 R 中的联合声明中清除双线?
How to clean double lines from joint statement in R?
已完成连接操作以将地址与自身进行比较。
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 姓名、街道、邮政编码、城镇
C02
客户 2 姓名、街道 2、邮政编码 2、城镇 2
...
...
以下操作:
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
距离
C01
Client1 姓名、街道、邮政编码、城镇
C02
客户 2 姓名、街道 2、邮政编码 2、城镇 2
0.05486
C02
客户 2 姓名、街道 2、邮政编码 2、城镇 2
C01
Client1 姓名、街道、邮政编码、城镇
0.05486
...
...
...
...
...
此连接操作的输出与反向客户端信息加倍。距离值不是唯一的。如何对数据框进行子集化以避免那些双线?
为了去掉包含相同数据的行,可以根据包含的元素排序,这样包含同一对Client_Reference
的行之间没有区别,然后删除重复的。之后,您可以过滤包含与您相同的 Client_Reference
的那些。
sensible_matches <- sensible_matches[!duplicated(t(apply(sensible_matches,1,sort))),]
View(sensible_matches %>% filter(Client_Reference.x != Client_Reference.y))
已完成连接操作以将地址与自身进行比较。
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 姓名、街道、邮政编码、城镇 |
C02 | 客户 2 姓名、街道 2、邮政编码 2、城镇 2 |
... | ... |
以下操作:
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 | 距离 |
---|---|---|---|---|
C01 | Client1 姓名、街道、邮政编码、城镇 | C02 | 客户 2 姓名、街道 2、邮政编码 2、城镇 2 | 0.05486 |
C02 | 客户 2 姓名、街道 2、邮政编码 2、城镇 2 | C01 | Client1 姓名、街道、邮政编码、城镇 | 0.05486 |
... | ... | ... | ... | ... |
此连接操作的输出与反向客户端信息加倍。距离值不是唯一的。如何对数据框进行子集化以避免那些双线?
为了去掉包含相同数据的行,可以根据包含的元素排序,这样包含同一对Client_Reference
的行之间没有区别,然后删除重复的。之后,您可以过滤包含与您相同的 Client_Reference
的那些。
sensible_matches <- sensible_matches[!duplicated(t(apply(sensible_matches,1,sort))),]
View(sensible_matches %>% filter(Client_Reference.x != Client_Reference.y))