小编Qwa*_*neQ的帖子

计算 r 中点对之间的距离

假设我生成了 10 个随机点

x <- runif(10, min = -10, max = 10)
y <- runif(10, min = -10, max = 10)
Run Code Online (Sandbox Code Playgroud)

我想计算每对点之间的距离。所以我用

d <- dist(cbind(x,y)) 
Run Code Online (Sandbox Code Playgroud)

我得到了一个漂亮的 9*9 矩阵。

但是,如果我使用

d1 <- dist(rbind(x,y))
Run Code Online (Sandbox Code Playgroud)

结果我只得到了 1 个数字。

谁能为我解释一下吗?

r distance rbind cbind

4
推荐指数
1
解决办法
5485
查看次数

标签 统计

cbind ×1

distance ×1

r ×1

rbind ×1