我想从我的data.frame
只保留约1200行,但要删除其余的行,我必须使用"基因名称"可以在data.frame
中找到。
我的数据(只有几行):
> tbl_ready2
Gene.name X1_1 X1_2 X1_3 X1_4 X1_5 X1_6 X1_7 X1_8 X1_9 X1_10 X1_11 X1_12 X1_13 X1_14 X1_15 X1_16 X1_17
1 AT1G01050 0 0 0.000000 0.000000 0.0000000 0.0000000 0.7137613 0.0000000 1.1431194 0.0000 0.0000000 0 0.000000 0.0000000 0 0.0000000 0.000000
2 AT1G01080 0 0 1.912532 1.263598 0.9972625 0.8363335 0.9984333 1.0027375 0.7207666 0.0000 0.7155959 0 0.000000 0.0000000 0 0.0000000 0.000000
3 AT1G01090 0 0 0.000000 0.000000 0.0000000 0.1864505 0.0000000 0.1057995 0.7634527 0.9794 1.1207689 1 1.276209 0.9701439 0 0.8552922 0.000000
4 AT1G01220 0 0 0.000000 0.000000 0.0000000 0.0000000 0.0000000 0.0000000 1.0000000 0.0000 0.0000000 0 0.000000 0.0000000 0 0.0000000 0.000000
5 AT1G01320 0 0 0.000000 0.000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 0.0000 1.0000000 1 1.106175 0.8972847 0 0.6782750 1.313616
X1_18 X1_19 X1_20 X1_21 X1_22 X1_23 X1_24
1 0.0000000 0.000000 0 0.000000 0 0 0.0000000
2 0.0000000 0.000000 0 0.000000 0 0 0.5538011
3 1.0182444 2.138711 0 1.554696 0 0 1.6815517
4 0.0000000 0.000000 0 0.000000 0 0 0.0000000
5 0.7313952 1.268605 0 2.128264 0 0 1.0000000
名称向量(不是全部):
> vec
[1] AT1G02500 AT1G07780 AT1G08250 AT1G08630 AT1G09780 AT1G09795 AT1G10060 AT1G10070 AT1G11790 AT1G12230 AT1G13440 AT1G14810 AT1G15710 AT1G16300 AT1G17290
[16] AT1G17745 AT1G18500 AT1G18640 AT1G22020 AT1G22170 AT1G22410 AT1G23310 AT1G24807 AT1G24909 AT1G25083 AT1G25155 AT1G25220 AT1G29410 AT1G31180 AT1G31230
[31] AT1G31860 AT1G32380 AT1G32440 AT1G32480 AT1G33320 AT1G36370 AT1G44820 AT1G48470 AT1G48850 AT1G48860 AT1G50090 AT1G50110 AT1G54100 AT1G54340 AT1G55880
[46] AT1G55920 AT1G56190 AT1G58080 AT1G62800 AT1G63290 AT1G65930 AT1G69370 AT1G70580 AT1G71100 AT1G71920 AT1G72330 AT1G72810 AT1G74030 AT1G74040 AT1G75330
所以我尝试了这个功能。认为它应该有效,但它没有......
data <- tbl_ready[intersect(vec, tbl_ready[,1])]
有什么想法吗?
答案 0 :(得分:3)
您在示例中使用的是tbl_ready和tbl_ready2。如果tbl_ready2是您想要子集的data.frame,您可以尝试:
data<-tbl_ready2[tbl_ready2$Gene.name %in% vec,]