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
Post a Comment