title: conditional statements in data.table
body: <p>I am trying to use conditional statements to obtain some variables in a data table. Here's some simplified data, the code and the results: </p>
  
  <pre><code>&gt; dt
     id trial  bet outcome
  1: 11     1    1       6
  2: 11     2  456       2
  3: 11     3 3456       3
  4: 11     4  456       6
  5: 12     1   34       6
  6: 12     2 3456       2
  7: 12     3   12       4
  8: 12     4  123       2
  
  dt1=dt[,list(
  nbet=nchar(bet),
  if (nchar(bet)&gt;2.5) riskybet=1 else riskybet=0,
  if (grepl(outcome,bet)==TRUE) win=1 else win=0),
  by='id,trial']
  
  &gt; dt1
     id trial nbet V2 V3
  1: 11     1    1  0  0
  2: 11     2    3  1  0
  3: 11     3    4  1  1
  4: 11     4    3  1  1
  5: 12     1    2  0  0
  6: 12     2    4  1  0
  7: 12     3    2  0  0
  8: 12     4    3  1  1
  </code></pre>
  
  <p>The conditional statements are working as they should but without the assigned variable names 'riskybet' and 'win', i.e. they appear as V2 and V3. What am I doing wrong?</p>