I have a dataset of rental advertisements. For each advert I have its precise latitude (and longitude but let's take just latitude now for simplicity). For each latitude I have calculated boundaries approx. 2 kms north- and southwards (latmin and latmax):
advert_id locality_public_lat latmin latmax
1 10083631 49.5794 49.56143 49.59737
2 10247827 50.0546 50.03663 50.07257
3 10647798 50.0910 50.07303 50.10897
4 10584515 50.0906 50.07263 50.10857
I would like to know now how many of all the other adverts fall in these boundaries for each advert (take all values in locality_public_lat column and compare it with latmin and latmax in first row and yield a count for the first row; then repeat for all other rows).
So far I tried to aggregate the data using summary function but the problem is that it compares only latitudes within each row and therefore the result is not valid (just counts all rows).
summary <- data_prodej_3 %>%
group_by(advert_id, month_stats) %>%
summarise(pocet_inz = sum(locality_public_lat > latmin & locality_public_lat < latmax))
Is there a way to summarise the data the way I described?