2012-11-08 46 views
1

數合併兩個矩陣可以說我有2個矩陣看起來像這樣:如何與不同的行

structure(c(0.315789473684211, 0.315789473684211, 0.315789473684211, 
0.315789473684211, 0.315789473684211, 0.315789473684211, 0.315789473684211, 
0.315789473684211, 0.315789473684211, 0.315789473684211, 0.315789473684211, 
0.315789473684211, 0.315789473684211, 0.315789473684211), .Dim = c(14L, 
1L), .Dimnames = list(c("ch5_98500001", "ch5_99500001", "ch5_100500001", 
"ch5_101500001", "ch5_102500001", "ch5_103500001", "ch5_104500001", 
"ch5_105500001", "ch5_106500001", "ch5_110500001", "ch5_111500001", 
"ch5_112500001", "ch5_113500001", "ch5_114500001"), "loh")) 
        loh 
ch5_98500001 0.3157895 
ch5_99500001 0.3157895 
ch5_100500001 0.3157895 
ch5_101500001 0.3157895 
ch5_102500001 0.3157895 
ch5_103500001 0.3157895 

structure(c(0.315789473684211, 0.315789473684211, 0.315789473684211, 
0.315789473684211, 0.315789473684211, 0.315789473684211, 0.315789473684211, 
0.315789473684211, 0.315789473684211, 0.315789473684211, 0.315789473684211, 
0.315789473684211, 0.315789473684211, 0.315789473684211, 0.315789473684211, 
0.315789473684211, 0.315789473684211, 0.315789473684211, 0.315789473684211, 
0.315789473684211, 0.315789473684211, 0.315789473684211, 0.315789473684211, 
0.315789473684211, 0.315789473684211, 0.315789473684211, 0.315789473684211, 
0.315789473684211, 0.315789473684211, 0.315789473684211, 0.315789473684211, 
0.315789473684211, 0.315789473684211, 0.315789473684211, 0.315789473684211, 
0.315789473684211, 0.315789473684211, 0.368421052631579, 0.368421052631579, 
0.368421052631579, 0.368421052631579, 0.368421052631579, 0.368421052631579, 
0.368421052631579, 0.368421052631579, 0.368421052631579, 0.368421052631579, 
0.368421052631579, 0.368421052631579, 0.368421052631579, 0.368421052631579, 
0.368421052631579, 0.368421052631579, 0.368421052631579, 0.368421052631579, 
0.368421052631579, 0.368421052631579, 0.368421052631579, 0.368421052631579, 
0.368421052631579, 0.368421052631579, 0.368421052631579, 0.368421052631579, 
0.368421052631579, 0.368421052631579, 0.368421052631579, 0.368421052631579, 
0.368421052631579, 0.368421052631579, 0.368421052631579, 0.368421052631579, 
0.368421052631579, 0.368421052631579, 0.368421052631579, 0.368421052631579, 
0.368421052631579, 0.368421052631579, 0.368421052631579, 0.368421052631579, 
0.368421052631579, 0.368421052631579, 0.368421052631579, 0.368421052631579 
), .Dim = c(83L, 1L), .Dimnames = list(c("ch8_20500001", "ch8_21500001", 
"ch8_22500001", "ch8_23500001", "ch8_24500001", "ch8_25500001", 
"ch8_26500001", "ch8_27500001", "ch8_28500001", "ch18_500001", 
"ch18_1500001", "ch18_2500001", "ch18_3500001", "ch18_4500001", 
"ch18_5500001", "ch18_6500001", "ch18_7500001", "ch18_8500001", 
"ch18_9500001", "ch18_10500001", "ch18_11500001", "ch18_12500001", 
"ch18_13500001", "ch18_14500001", "ch18_15500001", "ch18_16500001", 
"ch18_17500001", "ch18_18500001", "ch18_19500001", "ch18_20500001", 
"ch18_21500001", "ch18_24500001", "ch18_25500001", "ch18_26500001", 
"ch18_27500001", "ch18_28500001", "ch18_29500001", "ch18_30500001", 
"ch18_31500001", "ch18_32500001", "ch18_33500001", "ch18_34500001", 
"ch18_35500001", "ch18_36500001", "ch18_37500001", "ch18_38500001", 
"ch18_39500001", "ch18_40500001", "ch18_41500001", "ch18_42500001", 
"ch18_43500001", "ch18_44500001", "ch18_45500001", "ch18_46500001", 
"ch18_47500001", "ch18_48500001", "ch18_49500001", "ch18_50500001", 
"ch18_51500001", "ch18_52500001", "ch18_53500001", "ch18_54500001", 
"ch18_55500001", "ch18_56500001", "ch18_57500001", "ch18_58500001", 
"ch18_59500001", "ch18_60500001", "ch18_61500001", "ch18_62500001", 
"ch18_63500001", "ch18_64500001", "ch18_65500001", "ch18_66500001", 
"ch18_67500001", "ch18_68500001", "ch18_69500001", "ch18_70500001", 
"ch18_71500001", "ch18_72500001", "ch18_73500001", "ch18_74500001", 
"ch18_75500001"), "loss")) 
        loss 
ch8_20500001 0.3157895 
ch8_21500001 0.3157895 
ch8_22500001 0.3157895 
ch8_23500001 0.3157895 
ch8_24500001 0.3157895 
ch8_25500001 0.3157895 
ch8_26500001 0.3157895 
ch8_27500001 0.3157895 
ch8_28500001 0.3157895 
ch18_500001 0.3157895 
ch18_1500001 0.3157895 
ch18_2500001 0.3157895 

,我希望他們能夠在1個data.frame或矩陣合併只是讓我有一個概述並且不需要在文件之間切換。但解決這個問題似乎比僅僅使用data.frame難一些。

任何人都知道怎麼不能得到不同行長度的問題?

+0

@ jem77bfp這也可能與3幀或更多的幀? –

+0

@ jem77bfp謝謝!清單工作完美 –

回答

1
merge(as.data.frame(loss), as.data.frame(loh), by="row.names") 

但它給出了空的數據框,因爲在兩個匹配的矩陣中沒有行名。你也可以做

merge(as.data.frame(loss), as.data.frame(loh), by="row.names", all=TRUE) 

對於多個數據幀我會使用函數Reduce

Reduce(merge, list(data1, ..., dataN))) 

確保您通過by參數merge爲好。