I have an nx p-matrix and would like to compute an nx n-matrix B defined as
B[i, j] = f(A[i,], A[j,])
where f is a function that takes arguments of the corresponding dimension. Is there a neat trick to figure this out in R? f is symmetric and positive definite (if this can help with the calculation).
EDIT: Pranaet asked to indicate f. This is a good point. Although I think it would be interesting to have an effective solution for any function, I would get a lot of mileage from efficient computation in the important case when f (x, y) is base :: norm (xy, type = 'F').
gappy source share