title: R Compare latitudes and summarise results for each row
body: <p>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):</p>
  <pre><code>  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
  </code></pre>
  <p>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).</p>
  <p>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).</p>
  <pre><code>summary &lt;- data_prodej_3 %&gt;%
    group_by(advert_id, month_stats) %&gt;%
    summarise(pocet_inz = sum(locality_public_lat &gt; latmin &amp; locality_public_lat &lt; latmax))
  </code></pre>
  <p>Is there a way to summarise the data the way I described?</p>