Similar to canberra distance - inconsistent results , I wrote my own distance calculation, but I would like to perform this for a much greater set of data, and then create a distance matrix from the results.
My initial function is
canb.dist <- function(x, j) sum((abs(x-j))/(abs(x)+abs(j)))
Now, I would like to apply this function to every pair of rows in my data frame, and then create a distance matrix from this calculation. Let's say my data is:
data<-data.frame(replicate(500,sample(1:100,50,rep=TRUE)))
I'm struggling on this next part, of how to apply this to every pair of rows and then create a matrix that essentially mimics
dist(data,method="canberra")
I've attempted:
for (y in 1:50)
{
for (z in 2:50)
{
canb.dist(data[y,1:500],data[z,1:500])
}
}
But clearly it doesn't. Is there a way to run through every pair and replicate a distance matrix manually?