我有一个要合并的具有不同行数的数据框列表。有一个可爱的解决方案可以合并我使用和工作的多个数据框:
> go.sigtop.l[c(1:3)]
$SRSF1_cyto
GoTerm PValue Fold.Enrichment
1 lipid kinase activity 0.0044501957 5.378668
2 general RNA polymerase II transcription factor activity 0.0070975052 4.840801
3 protein methyltransferase activity 0.0022675162 4.302935
4 N-methyltransferase activity 0.0089131138 3.850638
5 structure-specific DNA binding 0.0002666942 3.821685
6 purine NTP-dependent helicase activity 0.0007861753 3.377303
$SRSF1_total
GoTerm PValue Fold.Enrichment
1 translation factor activity, nucleic acid binding 1.460691e-04 6.953428
2 structural constituent of ribosome 8.530549e-03 3.948718
3 RNA binding 3.479534e-09 3.675900
4 nucleotide binding 9.800564e-04 1.638817
$SRSF2_cyto
GoTerm PValue Fold.Enrichment
1 protein-lysine N-methyltransferase activity 0.001722436 16.486352
2 lysine N-methyltransferase activity 0.001722436 16.486352
3 histone-lysine N-methyltransferase activity 0.001722436 16.486352
4 histone methyltransferase activity 0.003756630 12.607211
5 N-methyltransferase activity 0.007775608 9.741935
6 protein methyltransferase activity 0.008275521 9.525448
> merge.all <- function(by, ...) {
+ frames <- list(...)
+ df <- Reduce(function(x, y) { merge(x, y, by = by, all = TRUE) }, frames)
+ names(df) <- c(by, paste("V", seq(length(frames)), sep = ""))
+
+ return(df)
+ }
> go.df <- merge.all("GoTerm", go.sigtop.l[[1]], go.sigtop.l[[2]], go.sigtop.l[[3]])
> go.df
GoTerm V1 V2 V3 NA NA NA
1 general RNA polymerase II transcription factor activity 0.0070975052 4.840801 NA NA NA NA
2 histone-lysine N-methyltransferase activity NA NA NA NA 0.001722436 16.486352
3 histone methyltransferase activity NA NA NA NA 0.003756630 12.607211
4 lipid kinase activity 0.0044501957 5.378668 NA NA NA NA
5 lysine N-methyltransferase activity NA NA NA NA 0.001722436 16.486352
6 N-methyltransferase activity 0.0089131138 3.850638 NA NA 0.007775608 9.741935
7 nucleotide binding NA NA 9.800564e-04 1.638817 NA NA
8 protein-lysine N-methyltransferase activity NA NA NA NA 0.001722436 16.486352
9 protein methyltransferase activity 0.0022675162 4.302935 NA NA 0.008275521 9.525448
10 purine NTP-dependent helicase activity 0.0007861753 3.377303 NA NA NA NA
11 RNA binding NA NA 3.479534e-09 3.675900 NA NA
12 structural constituent of ribosome NA NA 8.530549e-03 3.948718 NA NA
13 structure-specific DNA binding 0.0002666942 3.821685 NA NA NA NA
14 translation factor activity, nucleic acid binding NA NA 1.460691e-04 6.953428 NA NA
但问题是列表中的数据帧数量会有所不同。无论列表中包含的数字如何,如何自动调用所有元素?我试过了:
merge.all("GoTerm", go.sigtop.l[c(1:length(names(go.sigtop.l)))])
但这没有用。
我知道许多类似问题的答案,但我所见过的没有一个能解决我的问题。干杯。