<p dir="ltr">I haven't checked yet what it does currently but what you wrote makes perfect sense. <br>
</p>
<div class="gmail_quote">On Nov 10, 2013 5:44 AM, "Arunkumar Srinivasan" <<a href="mailto:aragorn168b@gmail.com">aragorn168b@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
Hi everyone,
</div><div><br></div><div>To revive the discussion Gabor started here: <a href="http://r.789695.n4.nabble.com/Problem-with-FAQ-2-8-tt4668878.html" target="_blank">http://r.789695.n4.nabble.com/Problem-with-FAQ-2-8-tt4668878.html</a> and the (related, but subtly different) FR mnel filed here: <a href="https://r-forge.r-project.org/tracker/index.php?func=detail&aid=2693&group_id=240&atid=978" target="_blank">https://r-forge.r-project.org/tracker/index.php?func=detail&aid=2693&group_id=240&atid=978</a></div>
<div><br></div><div>Suppose you have:</div><div><br></div><div>require(data.table)</div>
<div><div>d1 <- data.table(id1 = c(1L, 2L, 2L, 3L), val = 1:4, key = "id1") <br>d2 <- data.table(id2 = c(1L, 2L, 4L), val2 = c(11, 12, 14),key = "id2")<br></div><div><span style="font-family:Verdana,Geneva,Helvetica,Arial,sans-serif"><br>
</span></div><div>Then as Gabor points out: `d1[d2, id1]` should *not* result in an error, because FAQ 2.8 states (copied from Gabor's post linked above):</div><div><br></div><div>1. The scope of X's subset; i.e., X's column names. <br>
2. The scope of each row of Y; i.e., Y's column names (join inherited scope) </div><div>…</div><div><br></div><div>In this case, the desired output for `d1[d2, id1]` should then be:</div><div><div> id1 id1</div><div>
1: 1 1</div><div>2: 2 2</div><div>3: 2 2</div><div>4: 4 NA</div></div><div><br></div><div>That's what I at least understand from what the documentation intends. </div><div><br></div><div>However, this recommends a subtle change to the current method of referring to columns, if we were to keep this idea. That is, consider the data.table "d3" as follows:</div>
<div><br></div><div>d3 <- copy(d2)</div><div>setnames(d3, names(d1))</div><div><br></div><div>Now, what should `d1[d3, id1]` give? The answer, I believe, is same as `d1[d2, id1]`. Why? Because, X's (here d1's) column names should be looked up first (as per FAQ 2.8). Therefore, corresponding to d2=c(1,2,4), the values for "id1" are c(1, (2,2), NA). Now, if the old behaviour is to be intended - here comes the "subtle change", then one should do:</div>
<div><br></div><div>d1[d3, i.d1] # referring to i's variables with the "i." notation.</div><div><br></div><div>I've managed to implement the first part where X's columns are looked up so that `d1[d2, id1]` doesn't result in error. However, I'd like to ensure that my understanding of the FAQ is right (and that the FAQ makes sense - it does to me).</div>
<div><br></div><div>Please let me know what you all think so that I can implement the second part and commit. This, I believe will let us get a step closer to the consistency in DT syntax.</div><div><br></div><div>Arun</div>
<div><br></div></div>
<br>_______________________________________________<br>
datatable-help mailing list<br>
<a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a><br></blockquote></div>