<div dir="ltr">Michael,<div><br></div><div>I agree a note in the documentation should make things clearer. Thanks for the post. </div><div>Matt has already written a bit on this change <a href="http://r.789695.n4.nabble.com/Indexing-by-a-logical-column-td4665153.html#a4665142">here</a> on a post from GSee. </div>
<div><br></div><div>Have filed a request so that we don't forget.</div><div><a href="https://r-forge.r-project.org/tracker/?func=detail&atid=5356&aid=5643&group_id=240">https://r-forge.r-project.org/tracker/?func=detail&atid=5356&aid=5643&group_id=240</a><br>
</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Apr 26, 2014 at 4:19 AM, Michael Smith <span dir="ltr"><<a href="mailto:my.r.help@gmail.com" target="_blank">my.r.help@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">A.K.,<br>
<br>
Thanks a lot for the link.<br>
<br>
Looking at `?data.table`, maybe the documentation could be changed to<br>
read something like this, with the text in bracket added:<br>
<br>
integer and logical vectors work the same way they do in<br>
\code{\link{[.data.frame}} (but see the \dQuote{Advanced} note below<br>
about an exception for single variable names).<br>
<br>
The thing is that I did read the documentation, but I stopped reading at<br>
that point because it said to expect the same behavior as with<br>
data.frame, which is not what happened in my example code. And based on<br>
your link to SO, other people have had the same issue too.<br>
<br>
M<br>
<br>
<br>
On 04/26/2014 09:15 AM, arun wrote:<br>
> Hi M,<br>
><br>
> Check this link:<br>
> <a href="http://stackoverflow.com/questions/16191083/subset-data-table-by-logical-column" target="_blank">http://stackoverflow.com/questions/16191083/subset-data-table-by-logical-column</a><br>
><br>
> A.K.<br>
><br>
><br>
<br>
<br>
On 04/26/2014 09:08 AM, Michael Smith wrote:> Here's another example,<br>
<div class="im HOEnZb">maybe more to the point. Shouldn't the second<br>
> line also work, since `b` is logical already?<br>
><br>
</div><div class="im HOEnZb">> DT <- data.table(a = 1:8, b = c(TRUE, FALSE))<br>
</div><div class="im HOEnZb">> DT[b] # Doesn't work.<br>
> DT[identity(b)] # Does work.<br>
><br>
<br>
<br>
><br>
</div><div class="HOEnZb"><div class="h5">> On Friday, April 18, 2014 7:53 AM, Michael Smith <<a href="mailto:my.r.help@gmail.com">my.r.help@gmail.com</a>> wrote:<br>
> Hi All,<br>
><br>
> This is about subsetting using logicals. The code below is<br>
> self-explanatory (I hope). Is this a bug or a feature?<br>
><br>
> Thanks,<br>
><br>
> M<br>
><br>
><br>
>> DT <- data.table(a = 1:8, b = c(TRUE, FALSE))<br>
>> ## This does *not* work, but it should (in my humble opinion).<br>
>> DT[b]<br>
> Error in eval(expr, envir, enclos) : object 'b' not found<br>
>> ## This does work, but seems a bit awkward, given that b is already<br>
>> ## logical.<br>
>> DT[b == TRUE]<br>
> a b<br>
> 1: 1 TRUE<br>
> 2: 3 TRUE<br>
> 3: 5 TRUE<br>
> 4: 7 TRUE<br>
>> ## With data.frame things work as expected.<br>
>> DF <- as.data.frame(DT)<br>
>> DF[DF$b, ]<br>
> a b<br>
> 1 1 TRUE<br>
> 3 3 TRUE<br>
> 5 5 TRUE<br>
> 7 7 TRUE<br>
>> sessionInfo()<br>
> R version 3.0.2 (2013-09-25)<br>
> Platform: x86_64-redhat-linux-gnu (64-bit)<br>
><br>
> locale:<br>
> [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C<br>
> LC_TIME=en_US.utf8<br>
> [4] LC_COLLATE=en_US.utf8 LC_MONETARY=en_US.utf8<br>
> LC_MESSAGES=en_US.utf8<br>
> [7] LC_PAPER=en_US.utf8 LC_NAME=C LC_ADDRESS=C<br>
><br>
> [10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.utf8<br>
> LC_IDENTIFICATION=C<br>
><br>
> attached base packages:<br>
> [1] stats graphics grDevices utils datasets methods base<br>
><br>
> other attached packages:<br>
> [1] data.table_1.9.2 colorout_1.0-1<br>
><br>
> loaded via a namespace (and not attached):<br>
> [1] plyr_1.8.1 Rcpp_0.11.1 reshape2_1.2.2 stringr_0.6.2<br>
> _______________________________________________<br>
> datatable-help mailing list<br>
> <a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
><br>
_______________________________________________<br>
datatable-help mailing list<br>
<a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br>
</div></div></blockquote></div><br></div>