[datatable-help] logicals in datatable i

Arunkumar Srinivasan aragorn168b at gmail.com
Fri May 24 18:40:06 CEST 2013


Gabor,  

Not sure if this is intended, but the there's a code that explicitly assigns NA_integer_ if `i` is NA in `[.data.table`:

if (is.logical(i)) {
    if (identical(i, NA))  
        i = NA_integer_
    else i[is.na(i)] = FALSE
}


So, if `i` is JUST `NA`, then it's replaced with NA_integer_. If there are more than 1 element and i has NA in them, they are replaced with FALSE.

For ex: doing  
DT1[as.logical(c(NA, NA))]

would result in recycling and lead to a 0 rows and 1 column empty data.table.  

Arun


On Friday, May 24, 2013 at 6:29 PM, Gabor Grothendieck wrote:

> The ?data.table page describing arg i says:
>  
> "integer and logical vectors work the same way they do in
> [.data.frame. Other than NAs in logical i are treated as FALSE and a
> single NA logical is not recycled to match the number of rows, as it
> is in[.data.frame."
>  
> however, I get this:
>  
> > packageVersion("data.table")
> [1] ‘1.8.9’
>  
> > DT1 <- data.table(a = 1:5)
> > DT1[as.logical(NA)]
> >  
>  
> a
> 1: NA
>  
> so it seems that if there is a single logical NA it not only is not
> recycled but it also is not regarded as FALSE (whereas the quoted
> statement seems to say a logical NA is regarded as FALSE in all
> cases).
>  
> Is this intended?
>  
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com (http://gmail.com)
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org (mailto:datatable-help at lists.r-forge.r-project.org)
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
>  
>  


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20130524/e734a1a5/attachment.html>


More information about the datatable-help mailing list