What is the best way to assign to multiple columns using data.table? For example:
f <- function(x) {c("hi", "hello")}
x <- data.table(id = 1:10)
I would like to do something like this (of course this syntax is incorrect):
x[ , (col1, col2) := f(), by = "id"]
And to extend that, I may have many columns with names stored in a variable (say col_names) and I would like to do:
x[ , col_names := another_f(), by = "id", with = FALSE]
What is the correct way to do something like this?