I have the following data.table
library(data.table)
x <- data.table(a = 1:3, b = 1:6)
And I would like to assign at the same time two columns by reference since both columns use the same type of check. Normally I would do: (Assign multiple columns using := in data.table, by group)
x[, c("col1", "col2") := list("Yes", b)]
But I need an ifelse
construction for it. So I tried:
x[, c("col1", "col2") := ifelse(a > 2, list("Yes", b), list("No", a))]
But this does not work, I get an error:
Supplied 2 columns to be assigned 6 items
How can I work around it?