[Zooimage-commits] r206 - pkg/zooimage/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 19 14:43:05 CEST 2012


Author: kevin
Date: 2012-06-19 14:43:05 +0200 (Tue, 19 Jun 2012)
New Revision: 206

Modified:
   pkg/zooimage/R/ZIRes.R
Log:
Modification of the function sampleBio because sapply doesn't calculate the total biomass

Modified: pkg/zooimage/R/ZIRes.R
===================================================================
--- pkg/zooimage/R/ZIRes.R	2012-06-19 12:31:16 UTC (rev 205)
+++ pkg/zooimage/R/ZIRes.R	2012-06-19 12:43:05 UTC (rev 206)
@@ -424,11 +424,13 @@
 		} else {
 			if (!inherits(groups, "list")) 
 				stop("'groups' must be a 'list' object")
- 			res <- if (length(groups) == 1 && groups=="") {
-				sum(Smp$Biomass)
+            if (length(groups) == 1 && groups=="") {
+				res <- sum(Smp$Biomass)
 			} else {
-				sapply(groups, function (g)
+				res <- sapply(groups, function (g)
 					sum(Smp$Biomass[Smp[, Predictions] %in% g]))
+#			# Problem: sapply doesn't calculate the total biomass
+    			if(isTRUE(as.numeric(res["total"]) == 0)) res["total"] <- sum(Smp$Biomass)
 			}
 			names(res) <- paste(header, names(groups))
 		}
@@ -514,11 +516,13 @@
 		} else {
 			if (!inherits(groups, "list")) 
 				stop("'groups' must be a 'list' object")
- 			res <- if (length(groups) == 1 && groups=="") {
-				sum(Smp$Biomass)
+ 			if (length(groups) == 1 && groups=="") {
+				res <- sum(Smp$Biomass)
 			} else {
-				sapply(groups, function (g)
+				res <- sapply(groups, function (g)
 					sum(Smp$Biomass[Smp[, Predictions] %in% g]))
+#			# Problem: sapply doesn't calculate the total biomass
+    			if(isTRUE(as.numeric(res["total"]) == 0)) res["total"] <- sum(Smp$Biomass)
 			}
 			names(res) <- names(groups)
 		}



More information about the Zooimage-commits mailing list