# [R] calculate Euclidean distances between populations in R with this data structure

David L Carlson dcarlson at tamu.edu
Fri Sep 5 16:42:03 CEST 2014

```There may be a specialized package for this in bioconductor, but it seems that you could just use aggregate() to calculate the means for each population and then use the results of that in dist().

?aggregate

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

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Ding, Yuan Chun
Sent: Thursday, September 4, 2014 3:11 PM
To: r-help at R-project.org
Subject: [R] calculate Euclidean distances between populations in R with this data structure

I want to calculate Euclidean distance between 12 populations, in each population there are 20 samples and each sample is measured for 100 genes (these are microarray data; the numbers here are just examples).
The equation I found is:
distance = sqrt{[sum(Average of xi -average of yi)^2] /n }, i=1 to n;
where xi and yi are the expression of gene i over two populations with p and q samples (x1, x2,...,xp), (y1, y2,...,yq), n is the number of genes.
part of data are pasted below
row.names pop1.1    pop1.2  pop1.3  pop1.4  pop2.1  pop2.2  pop2.3  pop2.4
7A5     5.38194 4.06191 4.88044 5.60383 6.23101 6.53738 4.80336 5.86136
A1BG    5.15155 4.29441 4.59131 4.90026 4.62908 4.48712 4.73039 4.46208
A1CF    4.22396 4.14451 4.41465 3.93179 4.89638 4.66109 4.20918 4.48107
A26C3   12.1969 12.4179 10.9786 11.7659 11.405  11.7594 11.1757 11.8128
How might one calculate these distances in R with this data structure?

Thanks,

Ding

---------------------------------------------------------------------
*SECURITY/CONFIDENTIALITY WARNING:
This message and any attachments are intended solely for the individual or entity to which they are addressed. This communication may contain information that is privileged, confidential, or exempt from disclosure under applicable law (e.g., personal health information, research data, financial information). Because this e-mail has been sent without encryption, individuals other than the intended recipient may be able to view the information, forward it to others or tamper with the information without the knowledge or consent of the sender. If you are not the intended recipient, or the employee or person responsible for delivering the message to the intended recipient, any dissemination, distribution or copying of the communication is strictly prohibited. If you received the communication in error, please notify the sender immediately by replying to this message and deleting the message and any accompanying files from your system. If, due to the security risks, you do not wi!
sh to receive further communications via e-mail, please reply to this message and inform the sender that you do not wish to receive further e-mail from the sender. (fpc5p)
---------------------------------------------------------------------

[[alternative HTML version deleted]]

______________________________________________
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.

```