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

发布于 2024-10-01 21:18:37 字数 551 浏览 0 评论 0原文

我的问题是如何在 R 系统中连接两个或多个数据帧?

例如:

我有两个数据框:

第一个:

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

第二个:

   x  y  z
1  1  1  1
2  4  5  7

我需要这个:

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

我尝试对每个向量使用追加,如下所示:

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

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

f<-do.call(rbind, mix)

但它没有像我需要的那样工作。我没有得到我的矩阵,我得到了一些不同的结构。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花之痕靓丽 2024-10-08 21:18:37

使用 rbind() 的想法是正确的,但它要简单得多。如果您的数据框被命名为“first”和“second”:

f <- rbind(first, second)

f 是新的数据框。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文