0

For my model I need to aggregate my raster datasets using standard deviation. Is there a 'fun' abbreviation for this purpose? I am currently using mean but wish to use standard deviation instead. This is my code

library(raster)
merge1 <- raster("temp_merge1.tif")
red1 <- aggregate(merge1, fact=16, fun=mean, expand=TRUE, na.rm=TRUE)
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63

1 Answers1

1

You can use any function that takes a vector of numbers and returns a single number. In this case you could use sd.

library(terra)
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
x <- aggregate(r, 10, fun=sd, na.rm=TRUE)

With the "raster" package

r <- raster(f)
x <- aggregate(r, 10, fun=sd, na.rm=TRUE)
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63