I want to add a large number of columns to a data.table in R.
The column names are held in a vector a
. How to do it?
x <- data.table(a=1,b=1)
f <- function(x) {list(0)}
The following works:
x <- x[, c("col1","col2","col3") := f()]
but the following doesn't:
a <- c("col1","col2","col3")
x <- x[, a := f()]
How do I add the columns defined within a
?