I would like to know how can I extract the values of the first diagonal from a distance matrix.
For example:
> mymatrix [,1] [,2] [1,] 1
One work around is to convert the dist object to matrix and then extract elements where row index is one larger than the column index:
dist
matrix
mat = as.matrix(dist(mymatrix)) mat[row(mat) == col(mat) + 1] # [1] 2.828427 3.000000 2.828427