【问题标题】:how to remove row which value were found in group before如何删除之前在组中找到值的行
【发布时间】:2019-05-20 13:21:45
【问题描述】:

我目前正在处理包含染色体开始和结束位置的基因组数据。我想识别与另一个区域重叠的基因组区域并将它们折叠成新的基因组区域。

虽然我可以通过 GenomicRanges 包确定哪些区域重叠,但它会将我返回到需要过滤掉的数据。我想要的是删除 B 列中的数据不在 A 列中的行

data<- read.csv(textConnection(
"index,queryhits, subjecthits
 1, 1,  530,
 2, 2,  545,
 3, 2,  799,
 4, 2,  93,
 5, 3,  415,
 6, 4,  745,
 7, 545,799,
 8, 545,93,
 9, 545,415,
 10, 545,745,
 "))

subjecthit 列中的值不应在 queryhit 列中。比如第2行queryhit列等于2,subjecthits列等于545,表示545和2号分组。

但是,queryhit 中的一个值可以是 545,我不想再计算一次,因为我要删除 queryhits 列中包含 545 值的行 预期输出是

    index queryhits  subjecthits
     1 1    530
     2 2    545
     3 2    799
     4 2    93
     5 3    415
     6 4    745

我的真实数据大约是 20000 行,所以我希望在 queryhit 和 subjecthits 列中都有一个唯一的数字。

感谢您的任何帮助或建议

【问题讨论】:

    标签: r dataframe unique


    【解决方案1】:

    我们可以使用%in% 创建一个逻辑索引,取反 (!) 并子集“数据”行

    data[!data$index %in% data$queryhits,]
    #   index queryhits subjecthits
    # 1     1       530          NA
    # 2     2       545          NA
    # 3     2       799          NA
    # 4     2        93          NA
    # 5     3       415          NA
    # 6     4       745          NA
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-04
      • 1970-01-01
      • 2020-09-23
      • 2020-09-18
      • 2017-12-26
      • 2021-05-09
      相关资源
      最近更新 更多