[英]extract from distance matrix based on maximum distance
I have a distance matrix of genetic distances between pairs of isolates eg: 我有一对隔离物之间遗传距离的距离矩阵,例如:
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")))
I have made a huge heatmap of ~ 5000 isolates but this is far to big to extract the interesting areas from by reading the labels and so I want to filter my distance matrix to get eg. 我已经制作了大约5000个隔离物的热图,但是通过阅读标签来提取有趣的区域是非常大的,所以我想过滤我的距离矩阵以获得例如。 all pairs of isolates with a distance < 0.5. 所有距离<0.5的隔离物对。
My output might look like: 我的输出可能如下所示:
B C 0.3
How can I do this? 我怎样才能做到这一点?
Something like this? 像这样的东西?
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.