【问题标题】:extract from distance matrix based on maximum distance根据最大距离从距离矩阵中提取
【发布时间】:2019-02-04 10:37:28
【问题描述】:

我有一个分离株对之间遗传距离的距离矩阵,例如:

structure(c(0, 0.5, 0, 0.5, 0, 0.3, 0, 0.3, 0), .Dim = c(3L, 
3L), .Dimnames = list(c("A", "B", "C"), c("A", "B", "C")))

我已经制作了约 5000 个隔离物的巨大热图,但这对于通过读取标签从中提取有趣区域来说太大了,所以我想过滤我的距离矩阵以获得例如。距离

我的输出可能如下所示:

B    C    0.3

我该怎么做?

【问题讨论】:

    标签: r


    【解决方案1】:

    这样的?

    m <- structure(
      c(0, 0.5, 0, 0.5, 0, 0.3, 0, 0.3, 0),
      .Dim = c(3L,
               3L),
      .Dimnames = list(c("A", "B", "C"), c("A", "B", "C"))
    )
    # we convert matrix m to long format
    m2 <-
      matrix(m, dimnames = list(t(outer(
        colnames(m), rownames(m), FUN = paste
      )), NULL))
    # and finally we subset it
    (vec <- m2[m2[, 1] < 0.5,])
    #> A A A C B B B C C A C B C C 
    #> 0.0 0.0 0.0 0.3 0.0 0.3 0.0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-11
      • 2019-03-04
      • 2016-12-06
      • 2011-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多