Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate the distances between pairs of points in r

Lets say I have generated 10 random points

x <- runif(10, min = -10, max = 10)
y <- runif(10, min = -10, max = 10)

and I want to calculate the distances between each pair of points. so I use

d <- dist(cbind(x,y)) 

and I got a nice 9*9 matrix.

However, if I use

d1 <- dist(rbind(x,y))

I only got 1 number as the result.

Can anyone explain this for me?

like image 425
QwayneQ Avatar asked Nov 15 '25 07:11

QwayneQ


1 Answers

rbind(x,y) has 2 rows, 10 columns and is interpreted as 2 points in 10-dimensional space. dist(rbind(x,y)) is calculating the Euclidean distance between these 2 points.

like image 146
fishtank Avatar answered Nov 17 '25 20:11

fishtank