将矢量输出转换为data.table中的列?

krh*_*hlk 5 r data.table

我通过将函数应用于data.table的某些子集来生成输出.我正在使用这样的函数:

data[, foo(args), by=list(Year, Month)]
Run Code Online (Sandbox Code Playgroud)

我的函数foo总是返回一个长度向量n.我得到这样的输出:

      Year Month           V1
   1: 1983     2 9.734669e-06
   2: 1983     2 9.165665e-06
   3: 1983     2 2.097477e-05
   4: 1983     2 3.803727e-05
Run Code Online (Sandbox Code Playgroud)

但我想要像

      Year Month           V1           V2           V3           V4 ...
   1: 1983     2 9.734669e-06 9.165665e-06 2.097477e-05 3.803727e-05 ...
Run Code Online (Sandbox Code Playgroud)

我甚至尝试过使用list(foo(args)),但没有帮助.或者输出应该是什么形式foo$V1, foo$V2 ...

Mat*_*wle 9

尝试

data[, as.list(foo(args)), by=list(Year, Month)] 
Run Code Online (Sandbox Code Playgroud)

或改变foo以返回list而不是vector.