文件mart_export.txt3如下所示,可以看到,ENSG00000002016的第二列有很多不同的内容:
现在想要把相同ID的行进行合并,生成新的文件mart_export.txt4如下所示:
则可以使用命令:
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)