[datatable-help] Bug when by=key(DT)

Matthew Dowle mdowle at mdowle.plus.com
Fri Feb 25 00:53:32 CET 2011


Thanks Steve. That was a strange one. Bug #1298 raised, fixed and test
added.

o    by=key(DT) now works when the number of rows is not
     divisible by the number of groups (#1298, an odd bug).

Matthew

On Wed, 2011-02-23 at 22:05 -0500, Steve Lianoglou wrote:
> Hi,
> 
> I'm running data.table 1.5.4 (but this also fails w/ data.table in SVN).
> 
> One of the bullet points in the news for version 1.5.3 was:
> 
>   o    'by' may now be a character vector of column names.
>        This allows syntax such as DT[,sum(x),by=key(DT)].
> 
> But when the result of the subgroup iteration/summary returns less
> rows than the original subgroup, it fails.
> 
> For example:
> 
> R> library(data.table)
> R> dt <- data.table(name=c('a', 'a', 'a', 'b', 'b', 'c', 'c', 'c'),
> start=sample(1:50, 8))
> R> dt$end <- dt$start + sample(1:50, 8)
> R> key(dt) <- 'name'
> 
> This is OK:
> 
> R> dt[, list(start=max(start), end=max(end)), by='name']
>      name start end
> [1,]    a    47  69
> [2,]    b    35  48
> [3,]    c    26  52
> 
> This isn't:
> 
> R> dt[, list(start=max(start), end=max(end)), by=key(dt)]
> Error in `[[<-.data.frame`(`*tmp*`, jj, value = 1:3) :
>   replacement has 3 rows, data has 8
> 
> 
> 




More information about the datatable-help mailing list