Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9194469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:25:16+00:00 2026-06-17T21:25:16+00:00

Is is possible to force a distance object from the stats package to be

  • 0

Is is possible to force a distance object from the stats package to be something other than 0?

Here I try forcing it to something else and I can alter the upper or lower but not the diagonals:

set.seed(10)
x <- matrix(rnorm(25), ncol = 5)
y <- dist(x, diag =TRUE)
z <- 1 - as.matrix(y)
as.dist(z, diag =TRUE)

gives:

           1          2          3          4          5
1  0.0000000                                            
2 -0.9030066  0.0000000                                 
3 -0.9803571 -1.9319785  0.0000000                      
4 -1.5249747 -2.3673155 -1.5928891  0.0000000           
5 -2.7903980 -2.8020380 -2.2491893 -1.5839067  0.0000000

rather than the expected:

           1          2          3          4          5
1  1.0000000                                            
2 -0.9030066  1.0000000                                 
3 -0.9803571 -1.9319785  1.0000000                      
4 -1.5249747 -2.3673155 -1.5928891  1.0000000           
5 -2.7903980 -2.8020380 -2.2491893 -1.5839067  1.0000000

Maybe I have to output it as a matrix object instead because there’s something about forcing the diagonals to be not 0 that causes it to not conform to the way “dist” objects are handled.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:25:17+00:00Added an answer on June 17, 2026 at 9:25 pm

    Not with dist(); it doesn’t store the diagonal, just a flag to indicate if it should be printed via the print() method.

    This is not unexpect; dist() is a compact way of storing distance matrices, not symmetric matrices in general. In a distance matrix, by definition, the distance between an observation and itself is 0. Hence dist() treats the diagonal as the trivial thing it is and doesn’t store it.

    If I wanted to do what you want to, I would use the guts of dist() and store the data as dist() does, in a function, say mydist() with class "mydist", but then write print.mydist() taking code from the print.dist() method, but using another value for the diagonal, and write as.matrix.mydist() to do the conversion to a matrix. Your class could could either store the values for the diagonal (if they varied) or just a single value that you want the diagonal to be.

    Essentially then, all you’d need to do is store the diagonal value(s) you want as an extra attribute, then provide print() and as.matrix() methods that drew from that attribute to print or populate the matrix.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to prevent user from writing letters to a textbox (i.e. force
Is it possible to force an web service client to talk from a specific
is it possible to force a thread to return from a call to a
Is it possible to force a static data member in inherited subclasses? Here is
Is it possible to force the server to download files from peer-to-peer networks just
Is it possible to force opened jQuery Isotope divs to open above all the other
Is it possible to force gpg to do in-place encryption? In other words, to
Is is possible to force Grid view edit mode without using object data source,
Is it possible to force the iPhone to shutdown ( programmatically , of course)?
Is it possible to force the Facebook session to refresh, or alternatively, call the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.