[datatable-help] logicals in datatable i
Matthew Dowle
mdowle at mdowle.plus.com
Fri May 24 19:22:09 CEST 2013
Yes indeed it's intended and there is this in FAQ 2.17 (differences
between DF and DT) :
"DT[NA] returns 1 row of NA, but DF[NA] returns
a copy of DF containing NA throughout. The
symbol NA is type logical in
R, and is therefore recycled by [.data.frame. Intention was
probably
DF[NA_integer_]. [.data.table does this automatically for
convenience."
I see what you mean Gabor about that sentence in
?data.table. Thanks, will improve that wording.
Matthew
On 24.05.2013
17:40, Arunkumar Srinivasan wrote:
> 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 [1]
>>
_______________________________________________
>> datatable-help
mailing list
>> datatable-help at lists.r-forge.r-project.org [2]
>>
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
[3]
Links:
------
[1] http://gmail.com
[2]
mailto:datatable-help at lists.r-forge.r-project.org
[3]
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/f6a9c5dd/attachment.html>
More information about the datatable-help
mailing list