0

I have a very large dataset with dwellings. For every dwelling, I have the X and Y coordinates, and a boolean indicating whether the dwelling is a rental or not. For each dwelling, we need a radius of X meters, and get the number of rentals that fall into that radius.

I planned to do this with gBuffer but I am stuck at actually summing the number of rentals that fall into each zone. The current code, with an example DF, looks like this.

# Load packages
library(sp)
library(rgeos)

# Generate some sample data
set.seed(123)
df <- data.frame(id = 1:100, x = rnorm(100), y = rnorm(100))
df$rental <- sample(c(TRUE, FALSE), size = 100, replace = TRUE)


# create a SpatialPointsDataFrame object from the X and Y columns
coordinates(df) <- c("x", "y")

# create a buffer around each point with a specific radius
buffers <- gBuffer(df, width = 0.5, byid = TRUE)

The end results would be a fourth column, indicating how many rentals are surrounding each dwelling.

TvCasteren
  • 449
  • 3
  • 18

0 Answers0