I have a data table with a number of columns containing values. I have another column which defines which one of those columns whose value I need to select. I am having tr
The following should be memory efficient and a little easier to read/follow.
for (i in unique(d[["name.of.col"]]))
d[ name.of.col==i, value.of.col:=get(i) ]
d
value.1 value.2 name.of.col value.of.col
1: one two value.1 one
2: uno dos value.2 dos
3: 1 2 value.1 1