[Vegan-commits] r760 - pkg/vegan/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 26 09:55:54 CET 2009


Author: jarioksa
Date: 2009-03-26 09:55:54 +0100 (Thu, 26 Mar 2009)
New Revision: 760

Modified:
   pkg/vegan/R/mrpp.R
Log:
mrpp retains order of factor levels

Modified: pkg/vegan/R/mrpp.R
===================================================================
--- pkg/vegan/R/mrpp.R	2009-03-25 19:48:05 UTC (rev 759)
+++ pkg/vegan/R/mrpp.R	2009-03-26 08:55:54 UTC (rev 760)
@@ -22,13 +22,12 @@
     dmat <- as.matrix(dmat)
     diag(dmat) <- NA
     N <- nrow(dmat)
-    grouping <- as.factor(grouping)
-    ind <- as.numeric(grouping)
-    indls <- unique(ind)
-    ncl <- sapply(indls, function(x) sum(ind == x))
+    grouping <- factor(grouping)
+    indls <- levels(grouping)
+    ncl <- sapply(indls, function(x) sum(grouping == x))
     w <- switch(weight.type, ncl, ncl - 1, ncl * (ncl - 1)/2)
-    classdel <- classmean(ind, dmat, indls)
-    names(classdel) <- names(ncl) <- levels(grouping)[indls]
+    classdel <- classmean(grouping, dmat, indls)
+    names(classdel) <- names(ncl) <- indls
     del <- weighted.mean(classdel, w = w, na.rm = TRUE)
     E.del <- mean(dmat, na.rm = TRUE)
     ## 'Classification strength' if weight.type == 3
@@ -39,7 +38,7 @@
     }
     if (missing(strata)) 
         strata <- NULL
-    perms <- sapply(1:permutations, function(x) ind[permuted.index(N, 
+    perms <- sapply(1:permutations, function(x) grouping[permuted.index(N, 
         strata = strata)])
     m.ds <- numeric(permutations)
     m.ds <- apply(perms, 2, function(x) mrpp.perms(x, dmat, indls, 



More information about the Vegan-commits mailing list