title: Bray-Curtis Pairwise Analysis in R
body: <p>I am trying to calculate and visualize the Bray-Curtis dissimilarity between communities at paired/pooled sites using the Vegan package in R.</p>
  
  <p>Below is a simplified example dataframe:</p>
  
  <pre><code>Site = c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J") 
  
  PoolNumber = c(1, 3, 4, 2, 4, 1, 2, 3, 4, 4) 
  
  Sp1 = c(3, 10, 7, 0, 12, 9, 4, 0, 4, 3) 
  
  Sp2 = c(2, 1, 17, 1, 2, 9, 3, 1, 6, 7)
  
  Sp3 = c(5, 12, 6, 10, 2, 4, 0, 1, 3, 3)
  
  Sp4 = c(9, 6, 4, 8, 13, 5, 2, 20, 13, 3)
  
  df = data.frame(Site, PoolNumber, Sp1, Sp2, Sp3, Sp4)
  </code></pre>
  
  <p>"Site" is a variable indicating the location where each sample was taken
  The "Sp" columns indicate abundance values of species at each site.
  I want to compare pairs of sites that have the same "PoolNumber" and get a dissimilarity value for each comparison.</p>
  
  <p>Most examples suggest I should create a matrix with only the "Sp" columns and use this code:</p>
  
  <pre><code>matrix &lt;- df[,3:6]
  
  braycurtis = vegdist(matrix, "bray")
  
  hist(braycurtis)
  </code></pre>
  
  <p>However, I'm not sure how to tell R which rows to compare if I eliminate the columns with "PoolNumber" and "Site". Would this involve organizing by "PoolNumber", using this as a row name and then writing a loop to compare every 2 rows? 
  I am also finding the output difficult to interpret. Lower Bray-Curtis values indicate more similar communities (closer to a value of 0), while higher values (closer to 1) indicate more dissimilar communities, but is there a way to tell directionality, which one of the pair is more diverse?</p>
  
  <p>I am a beginner R user, so I apologize for any misuse of terminology/formatting. All suggestions are appreciated.</p>
  
  <p>Thank you</p>