[datatable-help] BUG: droplevels mangles subsetted data.table

pchalasani pchalasani at gmail.com
Tue Feb 21 18:38:33 CET 2012


 Surprising that this wasn't noticed before, or perhaps I'm not following
some recommended idiom to drop levels when using  data.table. The following
code illustrates the bug clearly: The bug remains regardless of whether I
use "subset" or simply use dt1 = dt[ name != 'a' ].



    d <- data.table(name = c('a','b','c'), value = 1:3)                                                                             
    dt <- data.table(d)                                                                                                                                        
    setkey(dt,'name')                                                                                                                                       
    dt1 <- subset(dt,name != 'a')  # or dt1 <- dt[ name != 'a' ]
    > dt1                                                                                                                                                  
          name value                                                                                                                                        
     [1,]    b     2                                                                                                                                        
     [2,]    c     3
                                                                                                                                        
    > droplevels(dt1)                                                                                                                                      
          name value                                                                                                                                        
     [1,]    b     1                                                                                                                                        
     [2,]    c     3 



--
View this message in context: http://r.789695.n4.nabble.com/BUG-droplevels-mangles-subsetted-data-table-tp4407694p4407694.html
Sent from the datatable-help mailing list archive at Nabble.com.


More information about the datatable-help mailing list