Not with dist() ; it does not save the diagonal, just a flag indicating whether to print it using the print() method.
This is not unexpected; dist() is a compact way to store distance matrices, not symmetric matrices in general. In the distance matrix, by definition, the distance between the observation and itself is 0. Therefore, dist() considers the diagonal as a trivial thing and does not save it.
If I wanted to do what you want, I would use the guts of dist() and save the data as dist() in a function, say mydist() with the class "mydist" , but then write print.mydist() taking the code from the method print.dist() , but using a different value for the diagonal and write as.matrix.mydist() to do the conversion to the matrix. Your class could either save the values ββfor the diagonal (if they changed), or just the single value that you want the diagonal to be.
Essentially, all you have to do is save the diagonal values ββyou want as an additional attribute, then provide the print() and as.matrix() methods, which are extracted from this attribute to print or fill the matrix.
source share