title: maximum date of multiple dates in R
body: <p>I've three dates d1,d2,d3 (there is a possibility that they could be NA)</p>
  
  <pre><code>id &lt;- c(1,2,3,4,5,6)
  
  d1 &lt;- c("09/30/2000", "","02/30/2000", "05/10/2003", "", "")
  d1 &lt;- as.Date(d1, "%m/%d/%y")
  
  d2 &lt;- c("6/30/2014", "6/15/2014","", "8/6/2011", "", "6/30/2014")
  d2 &lt;- as.Date(d2, "%m/%d/%y")
  
  d3 &lt;- c("9/5/2015", "9/2/2015","7/5/2015", "", "", "")
  d3 &lt;- as.Date(d3, "%m/%d/%y")
  
  
      mdata &lt;- data.frame(id,d1,d2,d3)
  
  
  id  date1   date2   date3
  1   9/30/2000   6/30/2014   9/5/2015
  2       6/15/2014   9/2/2015
  3   02/30/2000      7/5/2015
  4   5/10/2003   8/6/2011    
  5           
  6       6/30/2014   
  </code></pre>
  
  <p>I need to create a new var "maxdate" which is the max date among d1,d2,d3. If d1 is NA, then 
  maxdate = max(d2,d3). If all d1,d2,d3 are NA, then maxdate=NA.</p>
  
  <p>Here is the output:</p>
  
  <pre><code>id  date1   date2   date3   maxdate
  1   9/30/2000   6/30/2014   9/5/2015    9/5/2015
  2       6/15/2014   9/2/2015    9/2/2015
  3   02/30/2000      7/5/2015    7/5/2015
  4   5/10/2003   8/6/2011        8/6/2011
  5               NA
  6       6/30/2014       6/30/2014
  </code></pre>