I have very simple problem. Let's suppose I have data table:
dt = data.table(a = rnorm(10), b = rnrom(10))
I wanted to create a new variable in dt
like c = b * 2
. But I wanted to take both variable name b
and c
from other variables stored in string. Example
newvar = "c"
var = "b"
I can easily do this without using data table like this:
setDF(dt)
dt[newvar] = dt[var] * 2
I wanted to know, how can I do the same in data.table package syntax?