模糊匹配两个数据帧
我想合并两个数据帧DF1和DF2。
df1<-tibble(x=c("FIDELITY FREEDOM 2015 FUND", "VANGUARD WELLESLEY INCOME FUND"),y=c(1,2))
df2<-tibble(x=c("FIDELITY ABERDEEN STREET TRUST: FIDELITY FREEDOM 2015 FUND", "VANGUARD/WELLESLEY INCOME FUND, INC: VANGUARD WELLESLEY INCOME FUND; INVESTOR SHARES"),z=c(2020,2021))
我想基于x合并DF1和DF2。目前,我尝试使用模糊匹配并使用
fuzzy_join(df1,df2,match_fun = function(x,y) grepl(x, y))
它为我提供了如下输出,
In grepl(x, y) :
argument 'pattern' has length > 1 and only the first element will be used.
您是否有合并DF1和DF2的想法?我正在考虑如何编写match_fun函数,但我不确定如何进步。太感谢了!
I want to merge two data frames df1 and df2.
df1<-tibble(x=c("FIDELITY FREEDOM 2015 FUND", "VANGUARD WELLESLEY INCOME FUND"),y=c(1,2))
df2<-tibble(x=c("FIDELITY ABERDEEN STREET TRUST: FIDELITY FREEDOM 2015 FUND", "VANGUARD/WELLESLEY INCOME FUND, INC: VANGUARD WELLESLEY INCOME FUND; INVESTOR SHARES"),z=c(2020,2021))
I want to merge df1 and df2 based on x. Currently, I try fuzzy matching and use
fuzzy_join(df1,df2,match_fun = function(x,y) grepl(x, y))
It gives me the output as follows,
In grepl(x, y) :
argument 'pattern' has length > 1 and only the first element will be used.
Do you have any ideas for merging df1 and df2? I am thinking about how to write the match_fun function but I am not sure how to progress. Thank you so much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以使用
fuzzy_inner_join
或REGEX_INNER_JOIN
来自fuzzyjoin
软件包。或:
We could either use
fuzzy_inner_join
orregex_inner_join
fromfuzzyjoin
package.or: