不是很确定你的资料型态
帮你写了下面这个程式让你试试看
应该是可以动吧... ^^
A #左边的资料表
B #右边的资料表
A <- data.frame("gene_a"=c("A","B","C"),"Chrom"=c(1,"X",2))
B <- data.frame("Probe_b"=c("a1","a2","a3","a4","a5"),"Chrom2"=c(2,4,1,"X",1))
A
B
C <- list()
for(x in 1:nrow(A)){
C[[as.character(A$gene_a[x])]] <-
as.character(B$Probe_b[
which(is.element(as.character((B$Chrom2)),as.character(A$Chrom[x])))
])
}
※ 引述《yaowei2010 (yaowei)》之铭言:
: [问题类型]:
: 程式咨询(我想用R 做某件事情,但是我不知道要怎么用R 写出来)
: [软件熟悉度]:
: 新手(没写过程式,R 是我的第一次)
: [问题叙述]
: 资料的配对(如范例)
: [程式范例]:
: 表格如下
: gene_a Chromosome gene_start gene_end Probe_b Chromosome2 Chr_s Chr_e
: A 1 25000 50000 a1 2 175 200
: B X 1000 2000 a2 4 600 625
: C 2 0 800 a3 1 23575 23600
: a4 X 1010 1035
: a5 1 30000 30025
: 最后想变成这样
: gene_a match
: A a3 a5
: B a4
: C a1
: 有试着写过code
: 但gg QAQ
: 想问问强者怎么写? 或提示
: 程式码可贴于以下网站:
: http://ideone.com/
: http://codepad.org
: http://pastie.org/
: http://nopaste.info/
: http://pastebin.com/
: http://paste.plurk.com
: http://gist.github.com/
: http://nopaste.csie.org/
: ※ 编辑: yaowei2010 (140.112.129.5), 08/20/2014 16:22:15
: → yaowei2010: 两个资料 08/20 16:59
: → yaowei2010: (注 08/20 16:59