我有两个数据框
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]
答案 0 :(得分:1)
只需使用标准数据帧子集:
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%
运算符会测试GOBPID
中的B
是否在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,]