文件mart_export.txt3如下所示,可以看到,ENSG00000002016的第二列有很多不同的内容:

R: 使用tapply根据相同ID合并指定列

现在想要把相同ID的行进行合并,生成新的文件mart_export.txt4如下所示:

R: 使用tapply根据相同ID合并指定列

则可以使用命令:

phe = read.table("mart_export.txt3",header=T,check.names=F)
phe1 <- data.frame(
  Gene_stable_ID_unique = unique(phe$Gene_stable_ID),
  PDB_ID_paste = tapply(phe$PDB_ID, phe$Gene_stable_ID, paste0, collapse = ";"), row.names = NULL)
  write.table(phe1, file ="mart_export.txt4", sep =" ", row.names =FALSE, col.names =TRUE, quote =FALSE)

相关文章:

  • 2021-10-28
  • 2022-01-25
  • 2021-08-24
  • 2021-08-19
  • 2021-12-07
  • 2021-06-11
  • 2022-12-23
  • 2021-11-27
猜你喜欢
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
  • 2021-04-22
  • 2022-12-23
相关资源
相似解决方案