簡體   English   中英

抑制data.table j函數中的輸出

[英]suppress output in data.table j function

我想使用Rdata.table為一個id變量的不同值繪制一些ccf圖。 問題是ccf返回的值與data.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.

鑒於此問題:

我不關心返回值,只想看實際情節。

然后 :

x[, {ccf(a,b);NULL}, by=id]

它看起來相當丑陋(最終)返回一個矩陣:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM