title: How to calculate mean over date range in two data frames
body: <p>I'm using R, I have two data frames, one that contains columns for start date, end date, and station code while the other contains daily measures of salinity and station code. I would like to calculate the average salinity between the start and end date in the first data frame using the daily salinity measures in the second data frame.</p>
  
  <p>Here is the first data frame:</p>
  
  <pre><code>&gt; head(events)
  # A tibble: 6 x 5
    event_no duration date_start date_end   StationCode
       &lt;dbl&gt;    &lt;dbl&gt; &lt;date&gt;     &lt;date&gt;     &lt;chr&gt;      
  1        1        4 2003-01-01 2003-01-04 niwtawq    
  2        2        5 2003-01-06 2003-01-10 niwtawq    
  3        3        7 2004-05-25 2004-05-31 niwtawq    
  4        4        6 2004-10-31 2004-11-05 niwtawq    
  5        5        7 2006-08-02 2006-08-08 niwtawq    
  6        6        5 2007-08-07 2007-08-11 niwtawq 
  </code></pre>
  
  <p>and here is the second:</p>
  
  <pre><code>&gt; head(dat4)
     StationCode DateFormatted  Sal
  1:     niwtawq    2003-01-01 1.58
  2:     niwtawq    2003-01-02 1.19
  3:     niwtawq    2003-01-03 1.31
  4:     niwtawq    2003-01-04 1.56
  5:     niwtawq    2003-01-05 2.10
  6:     niwtawq    2003-01-06 1.33
  7:     niwtawq    2003-01-07 1.68
  8:     niwtawq    2003-01-08 1.83
  9:     niwtawq    2003-01-09 1.77
  10:     niwtawq    2003-01-10 1.56
  </code></pre>