title: subset xts with object in R
body: <p>There has to be a simple solution for this, but somehow I can not find it. I would like to subset an xts object by year (easy), but by using another object. </p>
  
  <pre><code>data &lt;- xts(1:1000, Sys.Date()+1:1000)
  data['2016',]  # this will give all 2016 data
  </code></pre>
  
  <p>Now I would like to do this:</p>
  
  <pre><code>year &lt;- as.numeric(2016)
  data['year',]
  </code></pre>
  
  <p>Obviously that does not work. Any help much appreciated</p>