For each point, the number of points (itself and coincident ones
included) within distance r of it. With r = 0 it counts coincident
points, the mode of exact locations; with r > 0 it is the fuzzy mode
of the crime-mapping literature, a fixed-radius scan centred on each
incident. Counts of nearby points overlap by design: each point counts
its own neighbourhood.
Arguments
- x, y
The points:
xandynumeric vectors of equal length; orxa matrix or data frame with columns namedxandy(orXandY, assf::st_coordinates()names them, orlonandlatwithlonlat = TRUE) andyNULL; orxan sf or sfc object of POINT geometries, whose coordinate reference system must agree withlonlat. An unnamed two-column matrix is read asxtheny; other columns are never taken by position. Vectors given separately (x,y, andwortwhere a function takes them) are matched by name when every one is named and no name repeats, as elsewhere in the package; otherwise by position. No missing or infinite values.- r
The radius: one number from 0, in the unit of the coordinates (metres when
lonlat = TRUE). Distances up to and includingrcount.- count
NULLfor points, or for zones: one whole count from 0 per zone (x,ythe zones' centroids); the result is then each zone's total count withinrof it, its own included.- metric
The distance:
"euclid"or"manhattan"(|dx| + |dy|), as inspwt()andjtsurf().- lonlat
FALSE(the default) whenxandyare planar coordinates in one length unit;TRUEwhen they are longitude and latitude in degrees, which are then projected to metres byeqproj()about their own centre, and centres are returned in degrees. It is never guessed.
Value
An integer vector, one count per point, in input order (with
count, a numeric vector of zone totals).