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です。

行の長さが異なるという問題を回避する方法を知っている人はいますか?

4

1 に答える 1

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

于 2012-11-08T11:32:18.217 に答える