[Raster-commits] r468 - in pkg/raster: . R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Aug 10 19:48:32 CEST 2009


Author: rhijmans
Date: 2009-08-10 19:48:32 +0200 (Mon, 10 Aug 2009)
New Revision: 468

Modified:
   pkg/raster/DESCRIPTION
   pkg/raster/R/predict.R
Log:


Modified: pkg/raster/DESCRIPTION
===================================================================
--- pkg/raster/DESCRIPTION	2009-08-07 00:50:40 UTC (rev 467)
+++ pkg/raster/DESCRIPTION	2009-08-10 17:48:32 UTC (rev 468)
@@ -1,8 +1,8 @@
 Package: raster
 Type: Package
 Title: Raster data handling for geographic data analysis and modeling
-Version: 0.8.9-22
-Date: 4-August-2009
+Version: 0.8.9-23
+Date: 10-August-2009
 Depends: methods, sp, rgdal (>= 0.5-33), R (>= 2.8.0)
 Author: Robert J. Hijmans & Jacob van Etten
 Maintainer: Robert J. Hijmans <r.hijmans at gmail.com> 

Modified: pkg/raster/R/predict.R
===================================================================
--- pkg/raster/R/predict.R	2009-08-07 00:50:40 UTC (rev 467)
+++ pkg/raster/R/predict.R	2009-08-10 17:48:32 UTC (rev 468)
@@ -1,3 +1,8 @@
+# Author: Robert J. Hijmans, r.hijmans at gmail.com
+# University of California, Davis
+# Date :  August 2009
+# Version 0.8
+# Licence GPL v3
 
 if (!isGeneric("predict")) {
 	setGeneric("predict", function(object, ...)
@@ -19,40 +24,29 @@
 		}
 		
 		if (dataContent(object) == 'all') {
-			indices <- 1:ncell(predrast)
-			rowvals <- data.frame( na.omit(cbind( indices, values(object, names=TRUE)) ) )
+			rowvals <- data.frame( values(object, names=TRUE))
 			if (haveFactor) {
 				for (i in 1:length(f)) {
 					rowvals[,f[i]] <- as.factor(rowvals[,f[i]])
 				}
 			}
 			
-			predv <- indices
-			predv[] <- NA
-			predv[indices] <- predict(model, rowvals[,-1], ...)
+			predv <- predict(model, rowvals, ...)
 			predrast <- setValues(predrast, predv)
 			if (filename(predrast) != "") {
 				predrast <- writeRaster(predrast)
 			}
 			return(predrast)
 		} else {
-			myIdVar <- 1:ncol(object)
-			predv <- 1:ncol(object)
 			for (r in 1:nrow(object)) {
 				object <- readRow(object, r)
-				
-				rowvals <- na.omit( cbind(myIdVar, values(object, names=TRUE)) )
+				rowvals <- data.frame( values(object, names=TRUE))		
 				if (haveFactor) {
 					for (i in 1:length(f)) {
 						rowvals[,f[i]] <- as.factor(rowvals[,f[i]])
 					}
 				}
-
-				indices <- rowvals[,1]
-				predv[] <- NA
-				if (length(indices) > 0) {
-					predv[indices] <- predict(model, data.frame(rowvals[,-1]), ...)
-				}
+				predv <- predict(model, rowvals, ...)
 				predrast <- setValues(predrast, predv, r)
 				predrast <- writeRaster(predrast, filetype=filetype, overwrite=overwrite)
 			}



More information about the Raster-commits mailing list