最佳答案
使用 data.table
分配给多列的最佳方法是什么? 例如:
f <- function(x) {c("hi", "hello")}
x <- data.table(id = 1:10)
我想这样做(当然这种语法是不正确的) :
x[ , (col1, col2) := f(), by = "id"]
为了扩展它,我可能有许多名称存储在一个变量中的列(比如 col_names
) ,我想这样做:
x[ , col_names := another_f(), by = "id", with = FALSE]
这样做的正确方法是什么?