title: Calculate average for specific date range in R
body: <p>I have two data frames:</p>
  
  <pre><code>Date &lt;- seq(as.Date("2013/1/1"), by = "day", length.out = 17)
  x &lt;-data.frame(Date)
  x$discharge &lt;- c("1000","1100","1200","1300","1400","1200","1300","1300","1200","1100","1200","1200","1100","1400","1200","1100","1400")
  x$discharge &lt;- as.numeric(x$discharge)
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>Date2 &lt;- c("2013-01-01","2013-01-08","2013-01-12","2013-01-17")
  y &lt;- data.frame(Date2)
  y$concentration &lt;- c("1.5","2.5","1.5","3.5")
  y$Date2 &lt;- as.Date(y$Date2)
  y$concentration &lt;- as.numeric(y$concentration)
  </code></pre>
  
  <p>What I am desperately trying to do is to the following: </p>
  
  <ol>
  <li>In data frame y the first measurement is for the period 2013-01-01 to 2013-01-07</li>
  <li>Calculate the average discharge for this period in data frame x</li>
  <li>Return the average discharge to data frame y in a new column next to the first measurement and continue with the next measurement</li>
  </ol>
  
  <p>I was having a look into function such as <code>dplyr</code> or <code>apply</code> but was not able to figure it out.</p>