将向量输出转换为data.table中的列? [英] Turn vector output into columns in data.table?
本文介绍了将向量输出转换为data.table中的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过将函数应用于data.table的某些子集来生成输出。我使用这样的功能:
I am generating output by applying function to some subsets of data.table. I am using function like this:
data[, foo(args), by=list(Year, Month)]
我的函数 foo
code> n 。我得到这样的输出:
My function foo
return always a vector of length n
. I am getting an output like this:
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
但我想要像
Year Month V1 V2 V3 V4 ...
1: 1983 2 9.734669e-06 9.165665e-06 2.097477e-05 3.803727e-05 ...
我甚至尝试使用 list(foo(args))
,它没有帮助。或者应该输出形式 foo $ V1,foo $ V2 ...
?
I even tried using list(foo(args))
, it didn't help. Or should the output be in form foo$V1, foo$V2 ...
?
推荐答案
尝试
data[, as.list(foo(args)), by=list(Year, Month)]
或更改 foo
a 列表
而不是向量
。
这篇关于将向量输出转换为data.table中的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文