Interesting. See FAQ 3.1, first bullet, for background on why it's doing
all.vars(jsub).
TRUE is a reserved word in R, so isn't considered a variable. T is a
variable (an object) in base holding the value TRUE (and may be masked by
user which is why T isn't recommended).
That leads to the more general bug :
> myvar = 6
> table2[A=="b",B*myvar]
Error in `[.data.table`(x, irows, all.vars(jsub), with = FALSE) :
undefined columns selected
It's just (I think) when i is integer or logical, and j uses a variable in
calling scope. When i is data.table, should be fine.
A workaround in the meantime is :
table2[A=="b",mean(B,na.rm=get("T"))]
Bug #1421 now raised, thanks :
https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1421&group_id=240&atid=975
Matthew
"Alexander Peterhansl" <[email protected]> wrote in message
news:fd59d3740610ab4388aa1bdc7fc9531d797...@crp11exhmbs01.gaincapital.com...
Dear Data Table Help List,
I am using data.table version 1.6 (with R version 2.13.0, 64-bit on Windows
7) and I've come across some strange behavior.
Please look at the following example, where I simply take the mean of two
numbers.
> table1 <- data.table(A=c("a","b","b"),B=c(4,5,NA))
> setkey(table1,A)
> table1["b",mean(B,na.rm=T)]
A V1
[1,] b 5
# EXPECTED OUTPUT
> table2 <- data.table(A=c("a","b","b"),B=c(4,5,NA))
> table2[A=="b",mean(B,na.rm=TRUE)]
[1] 5
# LESS EFFICIENT, BUT EXPECTED OUTPUT
> table2[A=="b",mean(B,na.rm=T)]
Error in `[.data.table`(x, irows, all.vars(jsub), with = FALSE) :
undefined columns selected
# WHY THE ERROR?
Any help would be much appreciated.
Regards,
Alex
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help