[datatable-help] Subsetting Bug?
Michael Smith
my.r.help at gmail.com
Fri Nov 7 10:17:29 CET 2014
Thanks, Øyvind, and yes, the same names are intentional. I guess it has
something to do with the scope in which the variable gets evaluated, and
that's why I have brackets around the CIK to refer to the "outer" CIK.
Nonetheless, I was expecting the same results in both calls.
On 11/07/2014 05:07 PM, Øyvind wrote:
> 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
> <mailto: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
> <mailto: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