[datatable-help] Output when using mean() with na.rm

Alexander Peterhansl APeterhansl at GAINCapital.com
Thu Jun 9 18:06:25 CEST 2011


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20110609/8976c2f6/attachment.htm>


More information about the datatable-help mailing list