0

我有两个数据框

    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]
4

1 回答 1

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%操作员测试一个GOBPIDfromB是否在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,]
于 2013-10-01T08:30:12.070 回答