本文介绍了R:模糊合并两个数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有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以获得
I want to merge abc and pqr to get
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))
我查看了一些较早发布的问题,但没有一个对我有用.
I looked at a few older posted questions, but none of them have worked for me.
推荐答案
这有效:
library(fuzzyjoin)
pqr <- pqr %>% stringdist_inner_join(abc, by = c(bin1 = "bin1"))
这篇关于R:模糊合并两个数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!