我通过将函数应用于 data.table 的某些子集来生成输出。我正在使用这样的函数:
data[, foo(args), by=list(Year, Month)]
我的功能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
但我想要类似的东西
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 ...
?
Try
data[, as.list(foo(args)), by=list(Year, Month)]
或改变foo
返回一个list
而不是一个vector
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)