Contact me:

R %in% ? merge() match()

in

> rc_24[1:5,]
           X24h.B3.1 X24h.B3.2 X24h.D.1 X24h.D.2
B3-1000001      1298      1176     1347     2165
B3-1000002       602       593      560     1030
B3-1000003       272       286      296      432
B3-1000004      4700      3895     4233     6764
B3-1000005       102       112      124      232

in错误

t1 <- rc_24[1:5,]
t2 <- rc_24[3:6,]
a = t1[,t1[,3]%in%t2[,3]]
a

(subscript) logical subscript too long

交换t1t2位置

t1 <- rc_24[1:5,]
t2 <- rc_24[3:6,]
a = t1[,t2[,3]%in%t1[,3]]
a
> a
           X24h.B3.1 X24h.B3.2 X24h.D.1
B3-1000001      1298      1176     1347
B3-1000002       602       593      560
B3-1000003       272       286      296
B3-1000004      4700      3895     4233
B3-1000005       102       112      124

match

c=match(t1[,3],t2[,3])
c
t1[c]
> c
[1] NA NA  1  2  3

match数据框

c=match(t1[,3],t2)
c

c
[1] NA NA 9 10 11

merge把基因名加到差异分析后

anno <- read.table("annotation.table.xls",sep = '\t',header = F,fill = T)
an = anno[,c(1,13)]
an\(gene <- an\)V13
an\(pp <- an\)V1
an <-an[,-c(1,2)]
head(an)

          pp        gene
1 B3-1000001        dnaA
2 B3-1000002 DPO3B, dnaN
3 B3-1000003        recF
4 B3-1000004        gyrB
5 B3-1000005           _
6 B3-1000006      K07024
rc3max=as.data.frame(rc3max)
rc3max$pp <- rownames(rc3max)
rc39_a = merge(rc3max,an,by='pp')
head(rc39_a)

head(rc39_a)
pp X3h.B3.1 X3h.B3.2 X24h.B3.1 X24h.B3.2 gene
1 B3-1000001 3940 2795 1298 1176 dnaA
2 B3-1000002 2968 1730 602 593 DPO3B, dnaN
3 B3-1000003 828 525 272 286 recF
4 B3-1000004 8008 7042 4700 3895 gyrB
5 B3-1000005 55 68 102 112 _
6 B3-1000006 401 424 230 219 K07024

match

posted @ 2020-10-27 23:26  impwa  阅读(137)  评论(0编辑  收藏  举报