1

I have a list of rasters which I want to combine into a single raster by getting the mean for each cell, ideally in the R terra package. According to this answer, the calc function in the raster package can be used to do this, but this won't take the SpatRaster objects from terra as arguments. Is there an equivalent method in terra?

1 Answer 1

4

The terra equivalent of raster::calc is terra::app so, to return the mean for a multi-band raster you would use:

rmean <- app(x, mean)

or to return the mean for an entire raster:

global(x, mean).

2
  • To clarify, if my rasters are r1, r2 and r3. Should I set x to be c(r1,r2,r3), or should x be rast(c(r1,r2,r3))?
    – A. Bollans
    May 11 at 10:40
  • @A.Bollans If r1 to r3 are raster files, use c(r1,r2,r3). If it are filenames, use rast(c(r1,r2,r3))
    – aldo_tapia
    May 11 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.