[datatable-help] newbie question on logical column indexing

Narayanan, Manikandan (NIH/NIAID) [E] manikandan.narayanan at nih.gov
Fri Sep 21 22:55:43 CEST 2012


Hi all,
  I am just starting to use data.table and finding it very convenient for handling large datasets.

  I am used to logical indexing of columns for wide data.frames, and wondering why the same cannot be achieved with data.table even after specifying with=FALSE.

Here is a toy example.
---
a = data.frame(x=1:3,y=4:6,z=7:9)
logidx = c(TRUE,TRUE,FALSE)
a[,logidx]
#   x y
# 1 1 4
# 2 2 5
# 3 3 6
a = data.table(a)
a[,c(1,2),with=FALSE] #works
a[,-3,with=FALSE] #works
a[,which(logidx),with=FALSE] #works
a[,logidx,with=FALSE] #doesn't work
# Error in `[.data.table`(a, , logidx, with = FALSE) : j out of bounds
---

  I'm trying to understand why the last command doesn't work? I'm using data.table 1.8.2 and R 2.15.0. Any help is appreciated.

Thanks,
Mani

PS: Apologies if you receive multiple copies, as I was having trouble subscribing to the email list.


More information about the datatable-help mailing list