I'm sure this has been answered before, but I can't find the thread for the life of me!
I am trying to use r to produce a list of all the distances between pairs of xy coordinates in a dataframe. The data is stored something like this:
ID = c('1','2','3','4','5','6','7')
x = c(1,2,4,5,1,3,1)
y = c(3,5,6,3,1,5,1)
df= data.frame(ID,x,y)
At the moment I can calculate the distance between two points using:
length = sqrt((x1 - x2)^2+(y1 - y2)^2).
However, I am uncertain as to where to go next. Should I use something from plyr or a for loop?
Thanks for any help!