[Raster-commits] r340 - pkg/raster/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Mar 10 07:22:16 CET 2009
Author: rhijmans
Date: 2009-03-10 07:22:15 +0100 (Tue, 10 Mar 2009)
New Revision: 340
Added:
pkg/raster/R/modalRaster.R
Log:
Added: pkg/raster/R/modalRaster.R
===================================================================
--- pkg/raster/R/modalRaster.R (rev 0)
+++ pkg/raster/R/modalRaster.R 2009-03-10 06:22:15 UTC (rev 340)
@@ -0,0 +1,31 @@
+# Author: Robert J. Hijmans
+# International Rice Research Institute
+# contact: r.hijmans at gmail.com
+# Date : March 2009
+# Version 0.8
+# Licence GPL v3
+
+
+setMethod("modal", signature(x='Raster'),
+ function(x, ..., ties='random', na.rm=FALSE){
+ rasters <- list(...)
+ if (class(x) == 'RasterLayer') {
+ if (length(rasters)==0) {
+ return(x)
+ }
+ }
+ rasters <- c(x, rasters)
+ rm(x)
+ for (i in 1:length(rasters)) {
+ if (class(rasters[[i]]) == 'RasterStack') {
+ r <- rasters[[i]]
+ rasters <- rasters[-i]
+ rasters <- c(rasters, unstack(r))
+ rm(r)
+ }
+ }
+ fun <- function(x){modal(x, ties=ties)}
+ return( .summaryRasters(rasters, fun, 'modal', na.rm=na.rm) )
+ }
+)
+
More information about the Raster-commits
mailing list