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 6697815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:30:18+00:00 2026-05-26T06:30:18+00:00

(Preface: I’m neither a statistician nor a programmer. I work in the humanities, so

  • 0

(Preface: I’m neither a statistician nor a programmer. I work in the humanities, so have mercy on my soul).

I need to calculate the Euclidean distance between a series of points in R. I’ve been using dist(), as follows:

> x <- c(0,0)
> y <- c(0,10)
> dist(rbind(x,y))
   x
y 10

So far, so good. But when I was looking at my results (with real numbers), they were horribly off. So much so that I figured my R script was grabbing data from the wrong columns. But I checked, and it isn’t.

So I started playing around with toy numbers, and I was in for a surprise. The above example (a vertical line) works correctly, as does the following (a horizontal line):

> x <- c(0,10)
> y <- c(0,0)
> dist(rbind(x,y))
   x
y 10

But when the line the two points form is diagonal, strangeness ensues:

> x <- c(0,10)
> y <- c(0,10)
> dist(rbind(x,y))
  x
y 0

A distance of 0? Huh? That can’t be right.

And when the points are identical (that’s quite possible in my data), we go down the rabbit hole:

> x <- c(0,0)
> y <- c(10,10)
> dist(rbind(x,y))
     x
y 14.14214

Should this not be 0? The points are identical, after all, so there can be no distance between them.

Just in case there’s something wrong with dist(), I tried to implement the formula manually, going by Wikipedia. Same results:

> sqrt(sum((x - y) ^ 2))
[1] 14.14214

As I said above, my math background is minimal, so I fully expect that the error here is mine. If so, please explain what it is and how to correct it. But from where I stand right now, it seems like something is very wrong.

And worst of all, I can’t analyze my data.

  • 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-05-26T06:30:18+00:00Added an answer on May 26, 2026 at 6:30 am

    It looks like you want dist(cbind(x, y)), not dist(rbind(x, y)).

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

Sidebar

Related Questions

Preface I have a need to create multiple copies of a search form (in
Preface: I'm a total Java noob...I just wrote Hello World yesterday. Have mercy on
Preface: I have two entities defined as a one-to-many relationship: A <<-------> B. B's
Preface: I am sure this is incredibly simple, but I have searched this site
To preface I am using Borland C++ and the VCL. I need some sort
Preface: I have a demo of the problem on my personal site (I hope
Preface: I have a MS Access 2010 front end running against a MySQL back
Preface The official python package python-openid (as distributed through pypi.org) does not work with
Preface I have three tables Customers, Individuals & Companies and a customer can be
Preface: I am horrible with java, and worse with java ui components. I have

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.