title: merge two dataframe with geometry and date R
body: <p>I do have a shape file and a dataframe with coordinates points, like the following:</p>
  <pre><code>#load package and 
  library(sf)
  library(dplyr)
  
  fname &lt;- system.file(&quot;shape/nc.shp&quot;, package=&quot;sf&quot;)
  nc &lt;- st_read(fname)
  
  plot(st_geometry(nc))
  set.seed(42)
      
   #create Data
    Data  &lt;-st_as_sf(data.frame(ID = 1:500,
            to_aggregate = runif(500, 0, 800),
            date = sample(seq(as.Date('1999/01/01'), as.Date('2001/01/01'), by=&quot;day&quot;), 500),
            geo =  sf::st_sample(nc, size = 500)))
                                  
      plot(st_geometry(Data), col = &quot;red&quot;, add = TRUE)
  </code></pre>
  <p>I would like to create a spatio-temporal dataframe, which have one observation for each <code>nc$name</code> each month. In this dataframe I want to sum up all my Data from <code>Data$to_aggregate</code> for each NAME and Month.If there is nothing to aggregate at a place and month it should be 0.</p>
  <p>I tried some attepts like:</p>
  <pre><code>nc&lt;- nc %&gt;%
         uncount(12) %&gt;%
         mutate(month =rep( 1:12, times = 100))
      
    Data1 &lt;-  st_intersection(nc, Data) %&gt;%  
               group_by(NAME, month) %&gt;% 
               summarize( aggregate= sum(to_aggregate))
    
  </code></pre>
  <p>A second apporach I just tried would be normal aggregate function of sf package, but I do not know how to implement the condition, that it only should aggregate in the same month. Any Idea?</p>
  <pre><code>Data1 &lt;- aggregate(Data[c(&quot;to_aggregate&quot;)], by = nc, FUN = sum)
  </code></pre>
  <p>Thanks.</p>