【问题标题】:R How do I add multiple annotations to same field of data.frame without overwriting?R如何在不覆盖的情况下将多个注释添加到data.frame的同一字段?
【发布时间】:2014-08-10 09:48:24
【问题描述】:

(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) 需要标注的数据集二

                      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) 告诉我 (2) 中的哪些注释需要添加到 (3) 中的何处。 (例如,(1)的子集告诉我们,(2)中第 246、247、248、249、250 行的注释都需要添加到(3)的第 1 行)。我的问题是(3)需要在同一个字段中有多个注释。现在我只能做出一个解决方案,每次添加新注释时都会覆盖 (3) 中的注释。

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

对于如何将多个注释添加到同一字段,您有一个聪明的解决方案吗?

谢谢

【问题讨论】:

    标签: r append dataframe


    【解决方案1】:

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

    例如,

    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
    

    【讨论】:

    • 谢谢,我做了一个 for 循环,然后在 data.frame 中的每个条目中添加了注释列表 :)
    猜你喜欢
    • 1970-01-01
    • 2018-09-30
    • 1970-01-01
    • 2022-12-06
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    • 2014-10-14
    • 2022-12-18
    相关资源
    最近更新 更多