Skip to content
Prev 343314 / 398506 Next

Euclidean Distance in 3 Dimensions

The dist() function works just fine in 2d or 3d or 100d. Your description of what you want to accomplish is not clear. Your code compares rows 1 and 2, then 2 and 3, then 3 and 4, and so on. You are comparing only adjacent points, but your description makes it sound like you want to compare point 1 to all the other points and see if they are in the same group and over 8 or in another group. If you type the following command you will see that your dat$X is just the diagonal of the distance matrix: 1 with 2, 2 with 3, 3 with 4 etc:

dist(dat[, 3:5])

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Don McKenzie
Sent: Thursday, August 21, 2014 1:44 PM
To: Patzelt, Edward
Cc: R-help at r-project.org
Subject: Re: [R] Euclidean Distance in 3 Dimensions

Ugh sorry.  I misread your message obviously. Cc?ing back to the list (as is the protocol)

I?m surprised no one else has replied. I?m a lightweight compared to others on the list.  It looks as if the dist() function has compiled code,
which suggests that there is some gnarly linear algebra underneath to speed it up even in 2D. Not for the faint-of-heart to hack.

Others?  ?dist3D??
On Aug 21, 2014, at 11:34 AM, Patzelt, Edward <patzelt at g.harvard.edu<mailto:patzelt at g.harvard.edu>> wrote:

            
Don McKenzie
Research Ecologist
Pacific Wildland Fire Sciences Lab
US Forest Service

Affiliate Professor
School of Environmental and Forest Sciences
University of Washington
dmck at uw.edu<mailto:dmck at uw.edu>





______________________________________________
R-help at r-project.org<mailto:R-help at r-project.org> mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.