>我有两个数据框
A ### data frame contain GO ids
GOBPID
G0:00987
GO:06723
GO:02671
GO:00654
GO:00132
B ### containing GO ids with their associated columns
GOBPID term
GO:08765 flavonoid synthesis
G0:00133 biosynthesis process
G0:00987 carotenoid synthesis
GO:06723 coumarin synthesis
GO:00824 metabolic process
GO:02671 leaf morphology
GO:00654 response to light
GO:00268 response to stress
GO:00135 pathogen defense
GO:00132 spindle formation
我只想从 A 和 B 中提取公共 ID,并删除其余行
#from A # from B # from B
G0:00987 G0:00987 carotenoid synthesis
GO:06723 GO:06723 coumarin synthesis
GO:02671 GO:02671 leaf morphology
GO:00654 GO:00654 response to light
GO:00132 GO:00132 spindle formation
并做了以下工作:
list of terms<- merge(A,B,by.x="GOBPID",by.y="GOBPID")
但是有一个错误,并返回了一个长度为 0 的数据帧,该数据帧只有列名但没有合并。
[1] GOBPID Term
<0 rows> (or 0-length row.names)
并再次尝试以下
merge(A,B,by.x="row.names",by.y="row.names")
它只是合并了两个数据框,但没有给我公共 ID。A 中的 5 个 id 仅与 B 中的前 5 个 id 匹配,并且不考虑仅合并公共 ID。
我还添加了两个数据集:
[dataset A][http://public.justcloud.com/dldzm0fnsp.4540049]
[dataset B][http://public.justcloud.com/dldzmx1758.4540049]
只需使用标准数据帧子集:
R> dd_B[dd_B$GOBPID %in% dd_A$GOBPID,]
GOBPID label
3 G0:00987 carotenoid synthesis
4 GO:06723 coumarin synthesis
6 GO:02671 leaf morphology
7 GO:00654 response to light
10 GO:00132 spindle formation
%in%
运算符测试来自B
的GOBPID
是否处于A
我认为您不需要第一列,因为它只是中间列的副本
上面示例的代码:
dd_A = data.frame(GOBPID = c("G0:00987", "GO:06723", "GO:02671", "GO:00654", "GO:00132"))
dd_B = read.table(textConnection('GO:08765 "flavonoid synthesis"
G0:00133 "biosynthesis process"
G0:00987 "carotenoid synthesis"
GO:06723 "coumarin synthesis"
GO:00824 "metabolic process"
GO:02671 "leaf morphology"
GO:00654 "response to light"
GO:00268 "response to stress"
GO:00135 "pathogen defense"
GO:00132 "spindle formation"'))
colnames(dd_B) = c("GOBPID", "label")
dd_B[dd_B$GOBPID %in% dd_A$GOBPID,]