这是一个高层次的一般性问题。 周围有一些类似的问题, 有着不同的、 更简洁的例子。 也许无法解答 。 conn
是矩阵 。
for (i in 2:dim(conn)[1]) {
for (j in 2:dim(conn)[1]) {
if ((conn[i, 1] == conn[1, j]) & conn[i, 1] != 0) {
conn[i, j] <- 1
conn[j, i] <- 1
}
else {
conn[i, j] <- 0
conn[j, i] <- 0
}
}
}
这直接来自集束群集软件包 cluscomp
。
My question is simply: is it possible to speed up the loop or to vectorise it? As an R beginner, I cannot see it and don t want to end up with frustration because it may not be possible. I ll accept any answer that can say yes or no and hint towards the potential amount of effort involved.