如何使用merge来cbind两个数据帧 [英] How can I use merge to cbind two dataframes

查看:218
本文介绍了如何使用merge来cbind两个数据帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个数据框:

df1 <- data.frame(matrix(rnorm(10*10),ncol=10))
df2 <- data.frame(matrix(rnorm(10*10),ncol=10))
colnames(df1) <- 1:10
colnames(df2) <- 11:20

如何使用 merge cbind 这些(我已经知道了 cbind 但我对 merge here。)

How do I use merge to cbind these (I already know about cbind but I am interested in the application of merge here).

推荐答案

行名。

merge(df1, df2, by=0)

注意结果中行的顺序!这些是按行名排序的词法。要获得正确的订单,请使用订单

Note the order of the rows in the result! These are lexicaly sorted by row name. To get the proper order, use order:

x <- merge(df1, df2, by=0)
x[order(as.numeric(x$Row.names)),]

这篇关于如何使用merge来cbind两个数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆