我有一对分离株之间遗传距离的距离矩阵,例如:
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个分离物的巨大的热图,但是通过读取标签来提取感兴趣的区域还远远不够,因此我想过滤距离矩阵以获得例如。距离<0.5的所有分离株对。
我的输出看起来像:
B C 0.3
我该怎么做?
答案 0 :(得分:0)
像这样吗?
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