[Picante-commits] r67 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed May 21 23:16:21 CEST 2008


Author: skembel
Date: 2008-05-21 23:16:21 +0200 (Wed, 21 May 2008)
New Revision: 67

Modified:
   pkg/R/phylodiversity.R
Log:
Fix mpd to not crash ses.mpd when 1 species in a sample

Modified: pkg/R/phylodiversity.R
===================================================================
--- pkg/R/phylodiversity.R	2008-05-21 18:32:48 UTC (rev 66)
+++ pkg/R/phylodiversity.R	2008-05-21 21:16:21 UTC (rev 67)
@@ -41,18 +41,25 @@
 	results
 }
 
-`mpd` <-
-function(samp,dis) {
-	N <- dim(samp)[1]
-	mpd <- numeric(N)
-	for (i in 1:N) {
-		sppInSample <- names(samp[i,samp[i,]>0])
-		sample.dis <- dis[sppInSample,sppInSample]
-		mpd[i] <- mean(sample.dis[lower.tri(sample.dis)])
-	}
-	mpd
+
+mpd <- function(samp, dis) 
+{
+    N <- dim(samp)[1]
+    mpd <- numeric(N)
+    for (i in 1:N) {
+        sppInSample <- names(samp[i, samp[i, ] > 0])
+        if (length(sppInSample) > 1) {
+            sample.dis <- dis[sppInSample, sppInSample]
+            mpd[i] <- mean(sample.dis[lower.tri(sample.dis)])
+        }
+        else{
+            mpd[i] <- 0
+        }
+    }
+    mpd
 }
 
+
 `mnnd` <-
 function(samp,dis) {
 	N <- dim(samp)[1]



More information about the Picante-commits mailing list