join two or more data frames in system R

北慕城南 提交于 2019-12-21 03:18:12

问题


My questions is how can join two or more data frames in system 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:

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

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

f<-do.call(rbind, mix)

But It didn't work like I needed. I didn't get my matrix, i got some different structure.


回答1:


You have the right idea using rbind(), but it's much more simple. If your data frames are named "first" and "second":

f <- rbind(first, second)

And f is the new data frame.



来源:https://stackoverflow.com/questions/4141588/join-two-or-more-data-frames-in-system-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!