My question is as follows:
I would like to generate column d
based on the information from column c
. Column c
provides the names of the columns from which to fetch data from, for that given row.
a b c d
1 5 3 a 5
2 8 6 b 6
3 12 8 a 12
My current method is very inefficient:
DT[, d:=mget(c)]
for(i in 1:nrow(DT)) { e[i] <- DT[,d][[i]][i]}
DT[,e:=e]
Appreciate it greatly if there is any one-liner solution.