合并具有不同长度的多个 table 并在 R 中形成一个 table

merge multiple table with different length and form a single table in R

我正在使用管道工 api 作为 api。我有多个子 table,其中所有 table 都与主键 (study_id) 相连,我想将所有 table 与单个主键合并以形成一个单身table。一些 table 具有 不同的长度

例如:- countries_of_origin_table 和 countries_of_recruitment_table 的长度不同 table

library(plumber)
library(tibble)
library(gwasrapidd)
library(dplyr)

#* @get /Studies 

detailData <- function(query = ""){
  print(query)
  studies <- get_studies(efo_trait = query)
  
  study <- studies@studies
  study
            
  publication <- studies@publications
  publication
  
  genotyping_techs_table <- studies@genotyping_techs
  genotyping_techs_table
  
  platforms_table <- studies@platforms 
  platforms_table
  
  ancestries_table <- studies@ancestries
  ancestries_table
  
  ancestral_groups_table <- studies@ancestral_groups
  ancestral_groups_table
  
  countries_of_origin_table <- studies@countries_of_origin
  countries_of_origin_table
  
  countries_of_recruitment_table <- studies@countries_of_recruitment
  countries_of_recruitment_table
  
  Studies_table = list(study, genotyping_techs_table, platforms_table,
   ancestries_table, ancestral_groups_table, countries_of_recruitment_table,
   countries_of_origin_table ,publication)
 

我试过这个来合并所有 table 但没有成功

collection <- merge(study, genotyping_techs_table, platforms_table,
                      ancestries_table, ancestral_groups_table, countries_of_recruitment_table,
                      countries_of_origin_table ,publication, by = "study_id" ,all=TRUE)
  
collection

请帮帮我

提前致谢

根据?merge,它一次只允许两个数据集加入

merge(x, y, ...)

哪里

x, y - data frames, or objects to be coerced to one.

一个选项是将数据集放在 list 中并使用 Reduce 进行顺序连接

lst1 <- list(study, genotyping_techs_table, platforms_table,
                  ancestries_table, ancestral_groups_table, 
         countries_of_recruitment_table,
                  countries_of_origin_table ,publication)

out <- Reduce(function(...) merge(..., by = "study_id" , all = TRUE), lst1)