我有2個文件如下從,使用R
文件1 2個不同的文件比較列:
Locus S1 S2 S3
loc1 87 56 77
loc2 34 55 75
loc3 12 09 78
loc4 34 67 89
loc5 78 65 46
文件2:
Locus S1 S2 S3
loc3 13 43 34
loc5 43 56 90
loc7 89 56 33
loc1 56 88 00
loc4 66 77 98
loc2 34 44 66
我要比較/匹配「軌跡「這兩個文件中的列,例如,在」new_output文件「中,我應該有來自File1的」locus「列的序列以及來自File2的各個基因座的值。
所以我的「new_output文件」應該是這樣的,
Locus S1 S2 S3
loc1 56 88 00
loc2 34 44 66
loc3 13 43 34
loc4 66 77 98
loc5 43 56 90
我想是這樣,
file1 <-read.delim(file="file1.txt",header=TRUE,sep="\t")
file2 <-read.delim(file="file2.txt",header=TRUE,sep="\t")
new_output <- file1[file1$Locus %in% file2$Locus,]
write.table(new_output,file="new_output.txt",sep="\t")
但那不是真的給我,結果我想要的方式。誰能幫我這個?並告訴我,我哪裏錯了?
謝謝您的幫助:) – Letin