[datatable-help] Subsetting Bug?

Øyvind oyvindbs at gmail.com
Fri Nov 7 10:07:09 CET 2014


Hi
I'm not sure if this was intentional and maybe not what you're asking, but
the problem is caused by the string CIK being called the same as the
variable CIK. Somehow in the first example "CIK" is understood as the
string and in the second as the variable. Thus in the second example you're
asking if the variable CIK == the variable CIK. If you change CIK to CIK2
everything works as expected:

CIK2 = "0000839087"
DT[CIK == (CIK2)][FileDate <= 10104]

          CIK FileDate
1: 0000839087    10081

DT[CIK == (CIK2)&FileDate <= 10104]

          CIK FileDate
1: 0000839087    10081

I guess someone else has to explain why data.table understands CIK and CIK
differently.


Øyvind

On Fri, Nov 7, 2014 at 9:51 AM, Michael Smith <my.r.help at gmail.com> wrote:

> Shouldn't the last two commands below yield identical results?
>
> DT <-
>     data.table(
>         CIK = c("0000060512", "0000839087"),
>         FileDate = c(8680, 10081))
> CIK = "0000839087"
> DT[CIK == (CIK)][FileDate <= 10104]
>
>           CIK FileDate
> 1: 0000839087    10081
>
> DT[CIK == (CIK) & FileDate <= 10104]
>
>           CIK FileDate
> 1: 0000060512     8680
> 2: 0000839087    10081
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20141107/05f4dc53/attachment.html>


More information about the datatable-help mailing list