[datatable-help] data.table 1.8.2: Problem using by= and a key that doesn't match any rows in the table
Michael Schermerhorn
mscherme at google.com
Fri Aug 3 21:54:02 CEST 2012
I recently updated from data.table 1.7.1 to 1.8.2 and found that my old
code using data.table
no longer works. I'm not sure if this is being caused by a bug in the new
version of data.table
or an intentional change to the way data.table works.
In 1.7.1, I could do the following:
> DT <- data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9)
> setkey(DT, x)
> DT[J(c("a", "b", "d")), sum(v), by=x]
x V1
[1,] a 6
[2,] b 15
[3,] <NA> NA
In 1.8.2, however, I get an error message:
> DT <- data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9)
> setkey(DT, x)
> DT[J(c("a", "b", "d")), sum(v), by=x]
Error in if (any(irows < 1L | irows > nrow(x))) stop("Internal error: some
irows<1 or >nrow(x)") :
missing value where TRUE/FALSE needed
Looking through the NEWS file I don't see any mention of this change (It's
possible that I just missed it).
If this an intentional change, I would ask that you consider reverting it.
It seems inconsistent that
DT[J(c("a", "b", "d"))] adds a new row to the table, but DT[J(c("a", "b",
"d")), sum(v), by=x]
causes an error.
Personally I think the following makes the most sense. But just reverting
back to what it did in 1.7.1
seems better than having an error.
> DT[J(c("a", "b", "d")), sum(v), by=x]
x V1
[1,] a 6
[2,] b 15
[3,] d NA
Thank you,
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20120803/008cbae8/attachment.html>
More information about the datatable-help
mailing list