[datatable-help] A new package multitable (data.list) remind me of a long existing feature request #202 and discussion thread

Matthew Dowle mdowle at mdowle.plus.com
Tue Oct 4 20:53:08 CEST 2011


On Sun, 2011-10-02 at 15:14 +0800, Branson Owen wrote:

> Oh, sorry, I was testing the syntax like: 
> 
> DT = data.table(A = 1:2, B = list('a', 2i))
> 
> It didn't work, and I though this feature has not been implemented.
> Thank you for pointing it out with a good example. 

Natural to assume that should work. Now in 1.6.7 :

o   data.table() now accepts list columns directly rather than
    needing to add list columns to an existing data.table; e.g.,
        
        DT = data.table(x=1:3,y=list(4:6,3.14,matrix(1:12,3)))
            
    Thanks to Branson Owen for reminding.
        
    Accordingly, one item has been added to FAQ 2.17 (differences
    between data.frame and data.table) : "data.frame(list(1:2,"k",1:4))
    creates 3 columns, data.table creates one list column"

    As before, list columns can be created via grouping; e.g.,
        
        DT = data.table(x=c(1,1,2,2,2,3,3),y=1:7)
        DT2 = DT[,list(list(unique(y))),by=x]
        DT2
             x      V1
        [1,] 1    1, 2
        [2,] 2 3, 4, 5
        [3,] 3    6, 7
            
    and list columns can be grouped; e.g.,
        
        DT2[,sum(unlist(V1)),by=list(x%%2)]
             x V1
        [1,] 1 16
        [2,] 0 12





More information about the datatable-help mailing list