I have one data table with the following columns:
name, x, y
a, 1, 2
b, 2, 3
c, 3, 1
I want to join this table with itself, keeping every row where name != name
and run a distance function on the x
and y
values from each side. The result should be in the format:
name1, name2, distance
I wrote the distance function like this:
dist <- function(a, b) sqrt((a$x-b$x)^2 + (a$y-b$y)^2)
I tried to use the outer
function, but it only takes vectors, not data tables and I tried using the various joins in dplyr but was unsuccessful.