title: ifelse with multiple condition for creating new variable in data.table R
body: <p>I have a <code>data.table</code> and want to create a new variable based on multiple conditions in an <code>ifelse</code> statement but what I get as a result seems to be strange.</p>
  
  <p>Let's imagine the following simplified example.</p>
  
  <pre class="lang-r prettyprint-override"><code>DT &lt;- data.table(replicate(2,sample(0:1,5,replace=TRUE)))
  
     V1 V2
  1:  1  0
  2:  1  1
  3:  1  1
  4:  1  0
  5:  0  1
  </code></pre>
  
  <p>I want to create a new variable based on the existing variables. I use the <code>ifelse</code> statement as follows:</p>
  
  <pre class="lang-r prettyprint-override"><code>DT[, new.var := ifelse(V1 &gt; 0, 1, 0)]
  DT[, new.var.mult := ifelse(V1 &gt; 0 &amp;&amp; V2 &gt; 0, 1, 0)]
  </code></pre>
  
  <p>However, this does not work in case of multiple conditions. (I am aware that this task could be solved easily without multiple condition but my problem is more complicated.)</p>
  
  <pre class="lang-r prettyprint-override"><code>   V1 V2 new_var new_var_multiple
  1:  1  0       1                0
  2:  1  1       1                0
  3:  1  1       1                0
  4:  1  0       1                0
  5:  0  1       0                0
  </code></pre>
  
  <p>What could be the problem here? </p>