How do you refer to variables in a
data.table if the variable names are stored in a character vector? For instance, this works for a
df <- data.frame(col1 = 1:3) colname <- "col1" df[colname] <- 4:6 df # col1 # 1 4 # 2 5 # 3 6
How can I perform this same operation for a data.table, either with or without
:= notation? The obvious thing of
dt[ , list(colname)] doesn't work (nor did I expect it to).