Calculates the concentration, which is the sum of all observations within a circle of a certain radius.
Usage
concentration(
sub,
full,
value,
lon_sub = lon,
lat_sub = lat,
lon_full = lon,
lat_full = lat,
radius = 200,
display_progress = TRUE
)Arguments
- sub
A data.frame of target points for which concentration risk is calculated. Must include at least columns for longitude and latitude.
- full
A data.frame containing reference points. Must include at least columns for longitude, latitude, and the value of interest to summarize.
- value
Column name in
fullcontaining the values to be summed.- lon_sub
Column name in
subfor longitude (default:lon).- lat_sub
Column name in
subfor latitude (default:lat).- lon_full
Column name in
fullfor longitude (default:lon).- lat_full
Column name in
fullfor latitude (default:lat).- radius
Numeric. Radius of the circle in meters. Must be positive (default: 200).
- display_progress
Logical. Whether to display a progress bar (
TRUE/FALSE). Default isTRUE.
Value
A data.frame equal to sub with an additional numeric column
concentration containing the summed values from full.
Details
This function uses a C++ backend for efficient distance calculations
(Haversine formula). For each point in sub, it finds all points in
full within the specified radius and sums their value.
Examples
# Target points
sub <- data.frame(location = c("p1", "p2"),
lon = c(6.561561, 6.561398),
lat = c(53.21369, 53.21326))
# Reference points with values
full <- data.frame(lon = c(6.5614, 6.5620, 6.5630),
lat = c(53.2132, 53.2140, 53.2150),
amount = c(10, 20, 15))
# Calculate concentration within 100 meters
concentration(sub, full, value = amount, radius = 100)
#> location lon lat concentration
#> 1 p1 6.561561 53.21369 30
#> 2 p2 6.561398 53.21326 30
