Sum values of Raster objects by row or column.

# S4 method for class 'Raster'
rowSums(x, na.rm=FALSE, dims=1L,...) 
# S4 method for class 'Raster'
colSums(x, na.rm=FALSE, dims=1L,...)

Arguments

x

Raster* object

na.rm

logical. If TRUE, NA values are ignored

dims

this argument is ignored

...

additional arguments (none implemented)

Value

vector (if x is a RasterLayer) or matrix

See also

See cellStats for summing all cells values

Examples

r <- raster(ncols=2, nrows=5)
values(r) <- 1:10
as.matrix(r)
#>      [,1] [,2]
#> [1,]    1    2
#> [2,]    3    4
#> [3,]    5    6
#> [4,]    7    8
#> [5,]    9   10
rowSums(r)
#> [1]  3  7 11 15 19
colSums(r)
#> [1] 25 30