title: using sapply on a vector of dates
body: <p>I have a function that adds a random integer to a date:</p>
  
  <pre><code>rand_to_date = function(date){
  newdate = as.Date(date) + sample(1:30, 1)
  return(as.Date(newdate))
  }
  </code></pre>
  
  <p>which works fine. However, if I attempt to use sapply to apply this function to a vector of dates, e.g.</p>
  
  <pre><code>test_dates = c('2001-01-01', '2002-02-02', '2003-03-03', '2004-04-04')
  </code></pre>
  
  <p>sapply will not return a vector of output in date format:</p>
  
  <pre><code> sapply(test_dates,rand_to_date)
   2001-01-01 2002-02-02 2003-03-03 2004-04-04 
   11329      11748      12115      12513
  </code></pre>
  
  <p>In contrast, lapply will return a list of dates. However, applying unlist to this output once again gives me a vector of numbers rather than dates. Nor does</p>
  
  <pre><code>sapply(sapply(test,rand_to_date), as.Date)
  </code></pre>
  
  <p>work. What's the simplest way for me to give a vector of these randomized dates as output?</p>