aggregate 17
Usage
## S4 method for signature 'Raster'
aggregate(x, fact, fun=mean, expand=TRUE, na.rm=TRUE, filename='', ...)
## S4 method for signature 'SpatialPolygons'
aggregate(x, by, sums, dissolve=TRUE, vars=NULL, ...)
Arguments
x Raster* object or SpatialPolygons* object
fact postive integer. Aggregation factor expressed as number of cells in each di-
rection (horizontally and vertically). Or two integers (horizontal and vertical
aggregation factor) or three integers (when also aggregating over layers). See
Details
fun function used to aggregate values
expand logical. If TRUE the output Raster* object will be larger then the input Raster*
object if a division of the number of columns or rows with factor is not an
integer
na.rm logical. If TRUE, NA cells are removed from calculations
filename character. Output filename (optional)
... if x is a Raster* object, additional arguments as for writeRaster
by character or integer. The variables (column names or numbers) that should be
used to aggregate (dissolve) the SpatialPolygons by only maintaining unique
combinations of these variables. The default setting is to use no variables and
aggregate all polygons. You can also supply a vector with a length of length(x)
sums list with function(s) and variable(s) to summarize. This should be a list of
lists in which each element of the main lists has two items. The first item
is function (e.g. mean), the second element is a vector of column names (or
indices) that need to summarize with that function. Be careful with charac-
ter and factor variables (you can use, e.g. ’first’ function(x)x[1] or ’last’
function(x)x[length(x)] or modal for these variables
vars deprecated. Same as by
dissolve logical. If TRUE borders between touching or overlapping polygons are removed
(requires package rgeos)
Details
Aggregation of a x will result in a Raster* object with fewer cells. The number of cells is the
number of cells of x divided by fact*fact (when fact is a single number) or prod(fact) (when
fact consists of 2 or 3 numbers). If necessary this number is adjusted according to the value of
expand. For example, fact=2 will result in a new Raster* object with 2*2=4 times fewer cells. If
two numbers are supplied, e.g., fact=c(2,3), the first will be used for aggregating in the horizontal
direction, and the second for aggregating in the vertical direction, and the returned object will have
2*3=6 times fewer cells. Likewise, fact=c(2,3,4) aggregates cells in groups of 2 (rows) by 3
(columns) and 4 (layers).