R如何在不覆盖的情况下向同一个data.frame字段添加多个注释?

时间:2014-06-19 18:18:44

标签: r append dataframe

(1)我有以下data.frame:

    queryHits subjectHits 
     <integer>   <integer> 
 1           1         246 
 2           1         247 
 3           1         248 
 4           1         249 
 5           1         250 

我有两个数据框:

(2)数据集与注释数据:

                                  celltype
                               <character>
1       Non-Gene Associated|Reg.Feats K562
2              Unclassified|Reg.Feats NHEK
3        Gene Associated|Reg.Feats GM06990
4         Unclassified|Reg.Feats MultiCell
5              Unclassified|Reg.Feats HSMM

(3)数据集2需要注释

                      annotation
                     <character>
1   Unclassified|Reg.Feats HUVEC
2   Unclassified|Reg.Feats HUVEC
3   Unclassified|Reg.Feats HUVEC
4   Unclassified|Reg.Feats HUVEC
5   Unclassified|Reg.Feats HUVEC

(1)告诉我在(3)中需要添加(2)中的注释。 (例如,(1)的子集告诉我们,来自(2)中的行246,247,248,249,250的注释都需要被添加到(3)的第1行)。我的问题是(3)需要在同一个字段中有多个注释。现在我只能做出一个解决方案,每次添加一个新的注释时,(3)中的注释都会被覆盖。

mcols(vcfData)$annotation[queryHits(hits)] <- mcols(encodeData)$celltype[subjectHits(hits)]

您是否有一个智能解决方案可以将多个注释添加到同一个字段?

由于

1 个答案:

答案 0 :(得分:0)

如果没有完整的示例,很难重现,但您可以尝试将注释添加为列表变量。

例如,

n = c(2, 3, 5) 
s = c("aa", "bb", "cc", "dd", "ee") 

s <- data.frame(s)
s$n <- list(n)

> s
   s       n
1 aa 2, 3, 5
2 bb 2, 3, 5
3 cc 2, 3, 5
4 dd 2, 3, 5
5 ee 2, 3, 5