Learn R Programming

terra (version 1.8-5)

rowSums: row/col sums and means for SpatRaster

Description

Sum or average values of SpatRaster layers by row or column.

Usage

# S4 method for SpatRaster
rowSums(x, na.rm=FALSE, dims=1L, ...) 
# S4 method for SpatRaster
colSums(x, na.rm=FALSE, dims=1L, ...) 
# S4 method for SpatRaster
rowMeans(x, na.rm=FALSE, dims=1L, ...) 
# S4 method for SpatRaster
colMeans(x, na.rm=FALSE, dims=1L, ...)

Value

matrix

Arguments

x

SpatRaster

na.rm

logical. If TRUE, NA values are ignored

dims

this argument is ignored

...

additional arguments (none implemented)

See Also

See global for summing all cells values

Examples

Run this code
r <- rast(ncols=2, nrows=5, nl=2, vals=1:20)
rowSums(r)
colSums(r)
colMeans(r)

Run the code above in your browser using DataLab