[R-sig-Geo] raster::calc with multiple arguments
Andy Bunn
Andy.Bunn at wwu.edu
Wed Jul 29 19:08:55 CEST 2015
Hi all, likely a dumb question. I want to use raster::calc with a function containing more than one argument. This violates the expectation of calc so I know the code below shouldn't work but I'm wondering what the best alternative is for calculating values for a new raster object from another raster object using a function with multiple arguments (e.g., fun2 below).
Regards and thanks in advance, Andy
require(raster)
r <- raster(ncols=36, nrows=18)
r[] <- 1:ncell(r)
# multiply values by 10
fun1 <- function(x) { x * 10}
# multiply values by alpha
fun2 <- function(x, alpha) { x * alpha}
rc1 <- calc(r, fun1) # works
rc2 <- calc(r, fun2, alpha=10) # doesn't work
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list