6

我想为using中变量的ccf不同值绘制一些图。问题是返回的值与. 我不关心返回值,只想看看实际的情节。一些代码:iddata.tableRccfdata.table

require(data.table)
x <- data.table(id=rep(1:10, each=10), a=rep(1:10,10), b=rep(10:1,10))
x[,ccf(a,b),by=id]
Error in `[.data.table`(x, , ccf(a, b), by = id) : 
All items in j=list(...) should be atomic vectors or lists. If you are trying something like j=list(.SD,newcol=mean(colA)) then use := by group instead (much quicker), or cbind or merge afterwards.
4

2 回答 2

6

鉴于问题中的这一点:

我不关心返回值,只想看看实际的情节。

然后 :

x[, {ccf(a,b);NULL}, by=id]
于 2012-11-09T23:47:33.040 回答
3

这看起来相当丑陋,因为它(最终)返回了一个矩阵:

xl <- x[,list(ccf(a,b)),by=id] # ugly mess
sapply(seq(1, 60, by=6), function(vecid) xl[[2]][[vecid]] )  # nice neat matrix

这可能更漂亮:

xl <- x[ , ccf(a,b)$acf, by=id]
xl
     id          V1
  1:  1  0.37575758
  2:  1  0.25757576
  3:  1  0.07878788
  4:  1 -0.14848485
  5:  1 -0.41212121
 ---               
126: 10 -0.41212121
127: 10 -0.14848485
128: 10  0.07878788
129: 10  0.25757576
130: 10  0.37575758
于 2012-11-09T23:17:38.183 回答