R:模糊合并两个数据框

时间:2019-05-31 18:49:40

标签: r fuzzyjoin

我有2个数据帧。

首先

abc <- data.frame(bin1 = c("0-25K", "25K-50K", "50K+"), group1 = c(1, 1, 2), bin2 = c("0-25", "25-50", "50+"), group2 = c(1, 2, 2))

pqr <- data.frame(bin1 = c("1_0-25K", "2_25K-50K", "3_50K+"),bin2 = c("0,25", "25,50", "50+"))

我想合并abc和pqr以获得

pqr <- data.frame(bin1 = c("1_0-25K", "2_25K-50K", "3_50K+"), group1 = c(1, 1, 2), bin2 = c("0,25", "25,50", "50+"), group2 = c(1, 2, 2))

我看了一些较早发布的问题,但没有一个对我有用。

Merging two Data Frames using Fuzzy/Approximate String Matching in R

1 个答案:

答案 0 :(得分:0)

这有效:

library(fuzzyjoin)
pqr <- pqr %>% stringdist_inner_join(abc, by = c(bin1 = "bin1"))