Skip to content
Prev 343319 / 398506 Next

Euclidean Distance in 3 Dimensions

So these two commands split the data frame by Cluster.Index and save them as a list, Clusters and then compute distance matrices on each group and save them as a list, Dists:

Clusters <- split(dta, dta$Cluster.Index)
Clusters
Dists <- lapply(Clusters, dist)
Dists

You should be able to process the matrices in each list to get what you want.

David C

From: Patzelt, Edward [mailto:patzelt at g.harvard.edu]
Sent: Thursday, August 21, 2014 2:58 PM
To: David L Carlson
Cc: Don McKenzie; R-help at r-project.org
Subject: Re: [R] Euclidean Distance in 3 Dimensions

Your first description is correct with slight modification "compare point 1 to all the other points in that Cluster.Index and see if any of euclidean distances are greater than 8; do this for each point (i.e. point 2, point 3) in that specific Cluster.Index (i.e. 45)"
On Thu, Aug 21, 2014 at 3:35 PM, David L Carlson <dcarlson at tamu.edu<mailto:dcarlson at tamu.edu>> wrote:
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> [mailto: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<mailto: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.



--
Edward H Patzelt | Clinical Science PhD Student
Psychology | Harvard University