Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

suppress output in data.table j function

I would like to plot some ccf plots for different values of an id variable in a data.table using R. The issue is that ccf returns a value that doesn't agree with data.table. I don't care about the return value but just want to see the actual plot. Some code:

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.
like image 565
Alex Avatar asked Nov 09 '12 23:11

Alex


1 Answers

Given this in the question :

I don't care about the return value but just want to see the actual plot.

then :

x[, {ccf(a,b);NULL}, by=id]
like image 149
Matt Dowle Avatar answered Sep 30 '22 14:09

Matt Dowle