[R-sig-Geo] summing rasters with a condition given by other rasters

Martin Brandt martin.brandt at mailbox.org
Sun May 10 13:37:44 CEST 2015


Hi Ben,

many thanks for the detailed answer. The code works fine, but when I use
rasters for eos and sos instead of numbers, i get an error:



b <- brick(system.file("external/rlogo.grd", package="raster"))

b <- addLayer(b,b,b)
b

sos <- raster(system.file("external/rlogo.grd", package="raster"))
eos <- raster(system.file("external/rlogo.grd", package="raster"))


sum_segment <- function(x, from = sos, to = eos, ...) {
  sum(x[from:to],...)
}

 s <- calc(b, sum_segment)

Error in .calcTest(x[1:5], fun, na.rm, forcefun, forceapply) : 
  cannot use this function

am I doing something wrong?




--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/summing-rasters-with-a-condition-given-by-other-rasters-tp7588222p7588226.html
Sent from the R-sig-geo mailing list archive at Nabble.com.



More information about the R-sig-Geo mailing list