簡體   English   中英

如何將R中的兩個數據集具有相同的行數但具有不同的列而沒有任何聯接條件?

[英]How to combine two datasets in R with same number of rows but different columns without any join condition?

假設我有兩個數據集:

D1:

    A    B    C
1   0    2    4
2   1    2    3
3   2    1    0

D2:

    D    E    
1   3    8    
2   1    5    
3   2    7    

我想要一個數據集,該數據集應該是以下兩者的組合:

    A    B    C    D    E
1   0    2    4    3    8
2   1    2    3    1    5
3   2    1    0    2    7

我已經嘗試過合並,但是交叉連接使它們成為3 * 3。

我們可以使用cbind

 do.call(cbind, list(d1, d2))

或使用dplyr

library(dplyr)
bind_cols(d1, d2)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM