首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >合并不同长度的多个表,在R中形成单个表

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

Stack Overflow用户
提问于 2020-12-27 19:28:43
回答 1查看 181关注 0票数 1

我使用水管工api作为api。我有多个子表,其中所有的表都与那里的主键(study_id)连接,我希望将所有表与单个主键合并成一个表。有些表具有不同长度的。

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

代码语言:javascript
复制
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)

我尝试过合并所有表,但是没有工作

代码语言:javascript
复制
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

请帮帮我

提前谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-27 19:29:59

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

合并(x,y,.)

哪里

x,y-数据帧或对象被胁迫到一个.

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

代码语言:javascript
复制
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)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65469643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档