R/normalize.R

#' Normalize a raster
#'
#' @param x  raster* object
#' @param ... additional functions to be passed to \code{\link[raster]{writeRaster}}
#' @description  Divide raster by the sum of all cells.
#' @export
#' @import raster

normalize <- function( x, ...){
  if(class(x)!="RasterLayer") stop("x must be a raster object")
  msum=raster::cellStats(x,sum, na.rm = TRUE )
  raster::calc(x,function(x)  x/msum ,...)
}

Try the bossMaps package in your browser

Any scripts or data that you put into this service are public.

bossMaps documentation built on May 2, 2019, 3:57 p.m.