[Vegan-commits] r1524 - in pkg/vegan: R inst

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Mar 7 06:39:17 CET 2011


Author: jarioksa
Date: 2011-03-07 06:39:16 +0100 (Mon, 07 Mar 2011)
New Revision: 1524

Modified:
   pkg/vegan/R/diversity.R
   pkg/vegan/inst/ChangeLog
Log:
diversity accepts vector input

Modified: pkg/vegan/R/diversity.R
===================================================================
--- pkg/vegan/R/diversity.R	2011-03-07 05:29:18 UTC (rev 1523)
+++ pkg/vegan/R/diversity.R	2011-03-07 05:39:16 UTC (rev 1524)
@@ -1,16 +1,23 @@
 `diversity` <-
   function (x, index = "shannon", MARGIN = 1, base = exp(1)) 
 {
-    x <- as.matrix(x)
+    x <- drop(as.matrix(x))
     INDICES <- c("shannon", "simpson", "invsimpson")
     index <- match.arg(index, INDICES)
-    total <- apply(x, MARGIN, sum)
-    x <- sweep(x, MARGIN, total, "/")
+    if (length(dim(x)) > 1) {
+        total <- apply(x, MARGIN, sum)
+        x <- sweep(x, MARGIN, total, "/")
+    } else {
+        x <- x/sum(x)
+    }
     if (index == "shannon")
         x <- -x * log(x, base)
     else
-        x <- x^2
-    H <- apply(x, MARGIN, sum, na.rm = TRUE)
+        x <- x*x
+    if (length(dim(x)) > 1) 
+        H <- apply(x, MARGIN, sum, na.rm = TRUE)
+    else
+        H <- sum(x, na.rm = TRUE)
     if (index == "simpson") 
         H <- 1 - H
     else if (index == "invsimpson") 

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-03-07 05:29:18 UTC (rev 1523)
+++ pkg/vegan/inst/ChangeLog	2011-03-07 05:39:16 UTC (rev 1524)
@@ -27,6 +27,12 @@
 	species occurs in a rarefied sample (= sampled without
 	replacement) of a given size.
 
+	* diversity: accepts a vector input. Among the functions
+	documented in ?diversity the following now accept vector input:
+	diversity, fisher.alpha, drarefy. The following do not accept a
+	vector, but input must be given as foo(t(x)): rarefy, rrarefy,
+	specnumber. 
+
 Version 1.18-23 (closed February 28, 2011)
 
 	* opened with the release of 1.17-7 based on version 1.18-22 on



More information about the Vegan-commits mailing list