title: Understanding function endpoints
body: <p>I have a time series of returns. In the first column I have all my dates. With this function (searching for hours) I finally managed to get the first value of every month. </p>
  
  <p>The problem was, that not always day 1 is the first value. Sometimes it is day 2,3,4,5 etc.</p>
  
  <p>Luckily with this function it all works:</p>
  
  <pre><code>library(xts)
  month&lt;- data[,1] ## all my dates    
  first.values &lt;- month[head(endpoints(month, "months") + 1, -1)]
  </code></pre>
  
  <p>What I want to understand though: Why the +1 and -1? That is all I would like to understand. </p>
  
  <p>I am not satisfied that the code works, I really want to understand.  Unfortunately I do not have enough reputation to contact or comment someone (since I found this code here).</p>