title: ifelse with data.table
body: <p>Here is my data:  </p>
  
  <pre><code>BuyDate       SellDate     Number
  2015-01-01    NA           1
  2015-01-01    2015-01-03   1
  2015-01-01    2015-01-03   -1
  2016-12-09    NA           -1
  </code></pre>
  
  <p>I want to create a new column <code>Start</code>, so I can have the following result.  </p>
  
  <pre><code>BuyDate       SellDate     Number    Start
  2015-01-01    NA           1         2015-01-01
  2015-01-01    2015-01-03   1         2015-01-01
  2015-01-01    2015-01-03   -1        2015-01-03
  2016-12-09    NA           -1        2016-12-09
  </code></pre>
  
  <p>The code is:  </p>
  
  <pre><code>data[,Start:=ifelse(Number=="1",BuyDate,ifelse(is.na(SellDate),BuyDate,SellDate))]
  </code></pre>
  
  <p>However, I get:  </p>
  
  <pre><code>BuyDate       SellDate     Number    Start
  2015-01-01    NA           1         1420070400
  2015-01-01    2015-01-03   1         1420070400
  2015-01-01    2015-01-03   -1        1420243200
  2016-12-09    NA           -1        1481241600
  </code></pre>
  
  <p>How can I solve this?  </p>
  
  <pre><code>str(data)
  Classes ‘data.table’ and 'data.frame':
   $BuyDate : POSIXct, format: "2015-01-01" "2015-01-01" "2015-01-01" "2016-12-09"
   $SellDate: POSIXct, format: NA "2015-01-03" "2015-01-03" NA
   $Number  : chr  "1" "1" "-1" "-1"
  </code></pre>