Two level loop over a matrix's row in R -
i need convert iteration below matrix operation.
a = certain_matrix(3,5) mat = matrix(0, 3,3) ( in 1:3 ) ( j in 1:3 ) mat[i,j] = certain_distance(a[i,], a[j,])
roughly need use apply(). however, cannot hold of row index in
apply(a, 1, function(x) xxx)
so how perform operation fast?
Comments
Post a Comment