简体   繁体   English

在系统R中连接两个或多个数据帧

[英]join two or more data frames in system R

My questions is how can join two or more data frames in system R? 我的问题是如何在系统R中加入两个或多个数据帧?

For example: 例如:

I have two data frames: 我有两个数据框:

first: 第一:

   x  y  z
1  3  2  4
2  4  5  7
3  5  6  8

second: 第二:

   x  y  z
1  1  1  1
2  4  5  7

I need this: 我需要这个:

   x  y  z
1  3  2  4
2  4  5  7
3  5  6  8
4  1  1  1
5  4  5  7

I tried to use append for each vector, like this: 我试图为每个向量使用append,如下所示:

for( i in 1:length(first)){ for(i in 1:length(first)){

  mix[[i]]<-append(first[i], second[i])} 

f<-do.call(rbind, mix) f <-do.call(rbind,mix)

But It didn't work like I needed. 但它不像我需要的那样工作。 I didn't get my matrix, i got some different structure. 我没有得到我的矩阵,我有一些不同的结构。

You have the right idea using rbind(), but it's much more simple. 你有正确的想法使用rbind(),但它更简单。 If your data frames are named "first" and "second": 如果您的数据框名为“first”和“second”:

f <- rbind(first, second)

And f is the new data frame. f是新的数据框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM