在 R 中为大矩阵计算距离矩阵的快速方法

Fast way to compute distance matrix in R for large matrix

我正在使用 R 计算大型矩阵的距离矩阵。矩阵有 39900 行和 1990 列:

set.seed(123)
#Matrix
M <- matrix(rnorm(39900*1990),nrow = 39900,ncol = 1990)

当我想计算距离矩阵时出现问题:

#Distance
d <- dist(M,method = 'euclidean')

电脑是icore3处理器,8GB内存,使用R 64位,24个多小时了,矩阵还没算出来

有没有什么方法可以使用 Rcpp 或其他方法来提高计算能力?我需要获取距离矩阵,本站其他方案均没有解决问题。

也许试试 distances 包:https://cran.r-project.org/web/packages/distances/distances.pdf

install.packages("distances")
library("distances")
set.seed(123)
M <- matrix(rnorm(39900*1990),nrow = 39900,ncol = 1990)
d <- distances(M)