aggregate | R Documentation |
spatial aggregation of thematic information in spatial objects
## S3 method for class 'Spatial'
aggregate(x, by = list(ID = rep(1, length(x))),
FUN, ..., dissolve = TRUE, areaWeighted = FALSE)
x |
object deriving from Spatial, with attributes |
by |
aggregation predicate; if |
FUN |
aggregation function, e.g. mean; see details |
... |
arguments passed on to function |
dissolve |
logical; should, when aggregating based on attributes, the
resulting geometries be dissolved? Note that if |
areaWeighted |
logical; should the aggregation of |
For as far as these functions use package rgeos, (lines, polygons, dissolve = TRUE), they are deprecated as rgeos will retire; try using sf::aggregate instead.
FUN
should be a function that takes as first argument a
vector, and that returns a single number. The canonical examples
are mean and sum. Counting features is obtained when
summing an attribute variable that has the value 1 everywhere.
The aggregation of attribute values of x
either over the
geometry of by
by using over for spatial matching,
or by attribute values, using aggregation function FUN
.
If areaWeighted
is TRUE
, FUN
is ignored and the
area weighted mean is computed for numerical variables, or if all
attributes are factor
s, the area dominant factor level (area
mode) is returned. This computes the intersection of x
and by
; see examples below. As this uses code from package
rgeos, it is deprecated as package rgeos will retire.
If by
is missing, aggregates over all features.
uses over to find spatial match if by
is a
Spatial object
Edzer Pebesma, edzer.pebesma@uni-muenster.de
data("meuse")
coordinates(meuse) <- ~x+y
data("meuse.grid")
coordinates(meuse.grid) <- ~x+y
gridded(meuse.grid) <- TRUE
i = cut(meuse.grid$dist, c(0,.25,.5,.75,1), include.lowest = TRUE)
j = sample(1:2, 3103,replace=TRUE)
x = aggregate(meuse.grid["dist"], list(i=i,j=j), mean, dissolve = FALSE)
spplot(x["j"], col.regions=bpy.colors())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.