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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Mar 13 04:01:48 CET 2009


Author: psolymos
Date: 2009-03-13 04:01:47 +0100 (Fri, 13 Mar 2009)
New Revision: 739

Modified:
   pkg/vegan/R/adipart.R
Log:
small improvements


Modified: pkg/vegan/R/adipart.R
===================================================================
--- pkg/vegan/R/adipart.R	2009-03-13 01:52:12 UTC (rev 738)
+++ pkg/vegan/R/adipart.R	2009-03-13 03:01:47 UTC (rev 739)
@@ -11,6 +11,8 @@
     rhs <- model.frame(formula, data, drop.unused.levels = TRUE)
     tlab <- attr(attr(rhs, "terms"), "term.labels")
     nlevs <- length(tlab)
+    if (nlevs < 2)
+        stop("provide at least two level hierarchy")
 
     ## part check proper design of the model frame
     noint <- attr(attr(attr(rhs, "terms"), "factors"), "dimnames")[[1]]
@@ -26,13 +28,9 @@
     rval[[1]] <- as.factor(rhs[,nlevs])
     rval[[1]] <- rval[[1]][drop = TRUE]
     nCol <- nlevs - 1
-    if (nlevs == 0)
-        stop("too few levels in the hierarchy")
-    if (nlevs > 1) {
-        for (i in 2:nlevs) {
-            rval[[i]] <- interaction(rhs[,nCol], rval[[(i-1)]], drop=TRUE)
-            nCol <- nCol - 1
-        }
+    for (i in 2:nlevs) {
+        rval[[i]] <- interaction(rhs[,nCol], rval[[(i-1)]], drop=TRUE)
+        nCol <- nCol - 1
     }
     rval <- as.data.frame(rval[rev(1:length(rval))])
     l2 <- sapply(rval, function(z) length(unique(z)))



More information about the Vegan-commits mailing list