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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Mar 7 12:01:35 CET 2011


Author: jarioksa
Date: 2011-03-07 12:01:32 +0100 (Mon, 07 Mar 2011)
New Revision: 1525

Modified:
   pkg/vegan/R/rarefy.R
   pkg/vegan/R/rrarefy.R
   pkg/vegan/R/specnumber.R
   pkg/vegan/inst/ChangeLog
   pkg/vegan/man/diversity.Rd
Log:
accept vector input

Modified: pkg/vegan/R/rarefy.R
===================================================================
--- pkg/vegan/R/rarefy.R	2011-03-07 05:39:16 UTC (rev 1524)
+++ pkg/vegan/R/rarefy.R	2011-03-07 11:01:32 UTC (rev 1525)
@@ -2,6 +2,9 @@
     function (x, sample, se = FALSE, MARGIN = 1) 
 {
     x <- as.matrix(x)
+    ## as.matrix changes an n-vector to a n x 1 matrix
+    if (ncol(x) == 1 && MARGIN == 1)
+        x <- t(x)
     if (!identical(all.equal(x, round(x)), TRUE))
         stop("function accepts only integers (counts)")
     if (missing(sample)) {

Modified: pkg/vegan/R/rrarefy.R
===================================================================
--- pkg/vegan/R/rrarefy.R	2011-03-07 05:39:16 UTC (rev 1524)
+++ pkg/vegan/R/rrarefy.R	2011-03-07 11:01:32 UTC (rev 1525)
@@ -3,6 +3,9 @@
 `rrarefy` <-
     function(x, sample)
 {
+    x <- as.matrix(x)
+    if (ncol(x) == 1)
+        x <- t(x)
     if (length(sample) > 1 && length(sample) != nrow(x))
         stop("length of 'sample' and number of rows of 'x' do not match")
     sample <- rep(sample, length=nrow(x))

Modified: pkg/vegan/R/specnumber.R
===================================================================
--- pkg/vegan/R/specnumber.R	2011-03-07 05:39:16 UTC (rev 1524)
+++ pkg/vegan/R/specnumber.R	2011-03-07 11:01:32 UTC (rev 1525)
@@ -1,5 +1,8 @@
-"specnumber" <-
+`specnumber` <-
     function(x, MARGIN = 1)
 {
-    apply(x > 0, MARGIN, sum)
+    if (length(dim(x)) > 1)
+        apply(x > 0, MARGIN, sum)
+    else
+        sum(x > 0)
 }

Modified: pkg/vegan/inst/ChangeLog
===================================================================
--- pkg/vegan/inst/ChangeLog	2011-03-07 05:39:16 UTC (rev 1524)
+++ pkg/vegan/inst/ChangeLog	2011-03-07 11:01:32 UTC (rev 1525)
@@ -27,12 +27,11 @@
 	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. 
+	* diversity, rarefy, rrarefy, specnumber: accept vector input. All
+	functions documented in ?diversity now accept vector input.
+	Function fisher.alpha and drararefy already accepted vectors.
 
+
 Version 1.18-23 (closed February 28, 2011)
 
 	* opened with the release of 1.17-7 based on version 1.18-22 on

Modified: pkg/vegan/man/diversity.Rd
===================================================================
--- pkg/vegan/man/diversity.Rd	2011-03-07 05:39:16 UTC (rev 1524)
+++ pkg/vegan/man/diversity.Rd	2011-03-07 11:01:32 UTC (rev 1525)
@@ -22,7 +22,7 @@
 }
 
 \arguments{
-  \item{x}{Community data, a matrix-like object.}
+  \item{x}{Community data, a matrix-like object or a vector.}
   \item{index}{Diversity index, one of \code{"shannon"},
     \code{"simpson"} or \code{"invsimpson"}.}
   \item{MARGIN}{Margin for which the index is computed. }



More information about the Vegan-commits mailing list