简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM