title: How to prevent ifelse() from turning Date objects into numeric objects
body: <p>I am using the function <code>ifelse()</code> to manipulate a date vector. I expected the result to be of class <code>Date</code>, and was surprised to get a <code>numeric</code> vector instead.  Here is an example:</p>
  
  <pre><code>dates &lt;- as.Date(c('2011-01-01', '2011-01-02', '2011-01-03', '2011-01-04', '2011-01-05'))
  dates &lt;- ifelse(dates == '2011-01-01', dates - 1, dates)
  str(dates)
  </code></pre>
  
  <p>This is especially surprising because performing the operation across the entire vector returns a <code>Date</code> object.</p>
  
  <pre><code>dates &lt;- as.Date(c('2011-01-01', '2011-01-02', '2011-01-03', '2011-01-04','2011-01-05'))
  dates &lt;- dates - 1
  str(dates)
  </code></pre>
  
  <p>Should I be using some other function to operate on <code>Date</code> vectors? If so, what function?  If not, how do I force <code>ifelse</code> to return a vector of the same type as the input?</p>
  
  <p>The help page for <code>ifelse</code> indicates that this is a feature, not a bug, but I'm still struggling to find an explanation for what I found to be surprising behavior.</p>