合并不同长度的多个表,并在R中形成一个表

合并不同长度的多个表,并在R中形成一个表,r,api,plumber,rjson,multidplyr,R,Api,Plumber,Rjson,Multidplyr,我正在使用管道工api作为api。我有多个子表,其中所有表都与主键(研究id)相连,我想将所有表与单个主键合并,形成一个表。有些表格的长度不同 例如:-原籍国和招聘国有不同的长度表 library(plumber) library(tibble) library(gwasrapidd) library(dplyr) #* @get /Studies detailData <- function(query = ""){ print(query) studi

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

例如:-原籍国和招聘国有不同的长度表

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)
 
图书馆(水管工)
图书馆(tibble)
图书馆(gwasrapidd)
图书馆(dplyr)
#*@get/Studies

detailData根据
?merge
,一次只允许连接两个数据集

合并(x,y,…)

在哪里

x、 y-数据帧或要强制为一个的对象

一个选项是将数据集放置在
列表中
并使用
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)

lst1感谢您的回复。我通过你的帖子得到了答案
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)