title: Strange behavior involving dates - "origin must be supplied"
body: <p>I have a data.table like so</p>
  
  <pre><code>dt &lt;- data.table(x=as.Date(c("2014-1-1", "2015-1-1", "2016-1-1")), y=as.Date(c(NA, "2015-6-1", NA)))
  dt
              x          y
  1: 2014-01-01       &lt;NA&gt;
  2: 2015-01-01 2015-06-01
  3: 2016-01-01       &lt;NA&gt;
  </code></pre>
  
  <p>I want to add a column <code>z</code> which is equal to y where y is not NA, and x otherwise.</p>
  
  <pre><code>dt[, z:=ifelse(is.na(y), x, y)]
  dt
              x          y     z
  1: 2014-01-01       &lt;NA&gt; 16071
  2: 2015-01-01 2015-06-01 16587
  3: 2016-01-01       &lt;NA&gt; 16801
  </code></pre>
  
  <p>But for some reason the above statement casts z to numeric.  If I try to convert it to a date with <code>as.Date</code> I get an error</p>
  
  <pre><code>dt[, z:=as.Date(ifelse(is.na(y), x, y))]
  Error in as.Date.numeric(ifelse(is.na(y), x, y)) : 'origin' must be supplied
  </code></pre>
  
  <p>What gives and how do I accomplish what I'm trying to do?</p>