Calculating FD

I've written functions in R that use the same matrix notation as in Petchey & Gaston (2002) . They are updated to account for the development to FD that we published in 2006 (Petchey & Gaston 2006 ) .
  
Instructions
  1. Gain an understanding of how to use R.
  2. Use the dist() and hclust() functions to calculate a dendrogram from a trait matrix.
  3. Paste this function (Xtree) into R. Use it to transform the object returned by hclust() into an object from which total branch is easy to calculate.
  4. The object returned by Xtree() is a list containing a species by branch matrix (H1) and a branch length vector (h2) (see Petchey & Gaston (2002) for more information on these).
  5. Follow the methods in Petchey & Gaston (2002) to get FD from H1 and h2.

 
Here's an example of using R to calculate the FD of a random community as it loses species; just paste the text into R. (Remember to paste in Xtree()!)
 
And here's an example of how to calculate the FD of communities that have different composition, and to see if FD correlates with an arbitrary measure of functioning)