r - When add a column to a data.table, what's then best way to add if else conditions? -


for example, like:

 dt[isflag, newcol:= a]  dt[!isflag, newcol:=b] 

or should this?

 dt[, newcol:= b]  dt[isflag, newcol:=a] 

or this?

 dt[, newcol:= if (isflag) else b] # works if isflag scalar 

or

dt[, newcol:= ifelse(isflag, a, b)] # works if isflag vector 

what best way?


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -