Skip to content

Instantly share code, notes, and snippets.

@johnbaums
Created October 30, 2017 23:57
Show Gist options
  • Save johnbaums/43b87f4861c5dbe52edf72212fcd58ef to your computer and use it in GitHub Desktop.
Save johnbaums/43b87f4861c5dbe52edf72212fcd58ef to your computer and use it in GitHub Desktop.
Faster standard deviation of RasterStack objects
rast_sd <- function(x) {
# x: a RasterStack
n <- nlayers(x)
m <- mean(x)
devsq <- (x - m)^2
sqrt(sum(devsq)/(n-1))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment