Estimates the local cell density around each cell using a circular neighbourhood of a given radius.
Value
The input data.table with an added density column representing
the number of neighbours within the specified radius.
Examples
dt <- data.table::data.table(
sample_id = "s1", cell_id = 1:50,
x = runif(50, 0, 100), y = runif(50, 0, 100)
)
result <- cell_density(dt, radius = 20)
head(result[, .(cell_id, density)])
#> cell_id density
#> <int> <num>
#> 1: 1 7
#> 2: 2 7
#> 3: 3 6
#> 4: 4 4
#> 5: 5 8
#> 6: 6 4