weighted.mean: Weighted mean of rasters

Description Usage Arguments Value See Also Examples

Description

Computes the weighted mean for each cell of a number or raster layers. The weights can be spatially variable or not.

Usage

1
2
3
4
5
## S4 method for signature 'RasterStackBrick,vector'
weighted.mean(x, w, na.rm=FALSE, filename='', ...)

## S4 method for signature 'RasterStackBrick,RasterStackBrick'
weighted.mean(x, w, na.rm=FALSE,filename='', ...)

Arguments

x

RasterStack or RasterBrick

w

A vector of weights (one number for each layer), or for spatially variable weights, a RasterStack or RasterBrick with weights (should have the same extent, resolution and number of layers as x)

na.rm

Logical. Should missing values be removed?

filename

Character. Output filename (optional)

...

Additional arguments as for writeRaster

Value

RasterLayer

See Also

Summary-methods, weighted.mean

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
b <- brick(system.file("external/rlogo.grd", package="raster"))

# give least weight to first layer, most to last layer
wm1 <- weighted.mean(b, w=1:3)

# spatially varying weights
# weigh by column number
w1 <- init(b, v='col')

# weigh by row number
w2 <- init(b, v='row')
w <- stack(w1, w2, w2)

wm2 <- weighted.mean(b, w=w)

Example output

Loading required package: sp

raster documentation built on June 18, 2021, 9:08 a.m.