I need to convert the iteration below into matrix operation.
a = certain_matrix(3,5)
mat = matrix(0, 3,3)
for ( i in 1:3 )
for ( j in 1:3 )
mat[i,j] = certain_distance(a[i,], a[j,])
Roughly I need to use apply(). However, I cannot get hold of the row index in
apply(a, 1, function(x) XXX)
So how to perform that operation fast?