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 <[email protected] > <mailto:[email protected]>> 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 > [email protected] > <mailto:[email protected]> > > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help > > _______________________________________________ datatable-help mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help
