[datatable-help] newbie question on logical column indexing

Matthew Dowle mdowle at mdowle.plus.com
Sat Sep 22 10:40:40 CEST 2012


Welcome.

That's FR#1797 (Allow j to be logical when with=FALSE) :
https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1797&group_id=240&atid=978

In the meantime can wrap with which().

> 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.
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>




More information about the datatable-help mailing list