Maxn is not an exact multiple of this length of column j when building a histogram from data.tables

I am trying to build a histogram from the results of the data.table grouping, but it seems I cannot get more than one diagram created before the following error occurred:

Error in [.data.table(DT, hist (V2, breaks = 2), by = V1): maxn (3) is not an exact multiple of this column length j (2)

This toy example should hope to demonstrate the problem.

require( data.table ) 
DT = data.table(c(1,1,2,2), c(1,2,3,4))

# This works
DT[,plot(V2,V2), by = V1] 

# This fails after the first plot
DT[,hist(V2, breaks = 2), by = V1] 

Any ideas on what I'm doing wrong?

+4
source share
1 answer

You need to wrap the expression jin list. If I find (or remember) the reason why I will edit it ...

DT[, list( hist(V2,breaks = 2) ) , by = V1 ]
+5
source

All Articles