如何组合两列基于两列的数据框?

编程入门 行业动态 更新时间:2024-10-26 10:40:53
本文介绍了如何组合两列基于两列的数据框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道我可以使用 plyr 及其朋友组合数据框,还可以使用 merge ,但是我不知道如何根据两列将两个数据框与多个列进行合并?

I know I can use the plyr and its friends to combine dataframes, and merge as well, but so far I don't know how to merge two dataframes with multiple columns based on 2 columns?

推荐答案

请参阅?merge ,其中指出:

By default the data frames are merged on the columns with names they both have, but separate specifications of the columns can be given by by.x and by.y.

这显然意味着 merge 将合并数据基于多列的框架。从文档中给出的最终示例:

This clearly implies that merge will merge data frames based on more than one column. From the final example given in the documentation:

x <- data.frame(k1=c(NA,NA,3,4,5), k2=c(1,NA,NA,4,5), data=1:5) y <- data.frame(k1=c(NA,2,NA,4,5), k2=c(NA,NA,3,4,5), data=1:5) merge(x, y, by=c("k1","k2")) # NA's match

此示例旨在演示使用无与伦比的,但它也说明了使用多个列的合并。您还可以在 x 和 y 中使用 by.x 和 by.y 。

This example was meant to demonstrate the use of incomparables, but it illustrates merging using multiple columns as well. You can also specify separate columns in each of x and y using by.x and by.y.

更多推荐

如何组合两列基于两列的数据框?

本文发布于:2023-10-23 16:07:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1521336.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组合   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!