<div>
                    Gabor,
                </div><div><br></div><div>X[Y] and Y[X] are not necessarily the same operations (meaning, they don't *have* to give the same output). However, merge(X,Y) and merge(Y,X) *have* to provide the same output (except for the column order and names). In that sense, a join is a bit different from a merge, no?</div>
                <div><div><br></div><div>Arun</div><div><br></div></div>
                 
                <p style="color: #A0A0A8;">On Friday, May 3, 2013 at 5:36 PM, Gabor Grothendieck wrote:</p>
                <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
                    <span><div><div><div>Yes, except that is not really what happens since match() only matches</div><div>one row whereas with mult="all", the default, all rows are matched</div><div>which is not really matching in the sense of match().  The current</div><div>naming confuses matching with joining and its really the latter that</div><div>is being done.</div><div><br></div><div>Regarding the existence of merge the advantage of [ is that it will</div><div>automatically only take the columns needed so merge is not really</div><div>equivalent to [ in all respects.  Furthermore having to use different</div><div>constructs for different types of merge seems awkward.</div><div><br></div><div><br></div><div>On Fri, May 3, 2013 at 11:27 AM, Eduard Antonyan</div><div><<a href="mailto:eduard.antonyan@gmail.com">eduard.antonyan@gmail.com</a>> wrote:</div><blockquote type="cite"><div><div>Btw the way I think about the "nomatch" name is as follows - normally X[Y]</div><div>tries to match rows of Y with rows of X, and then "nomatch" tells it what to</div><div>do when there is *no match*.</div><div><br></div><div><br></div><div>On Fri, May 3, 2013 at 10:23 AM, Eduard Antonyan <<a href="mailto:eduard.antonyan@gmail.com">eduard.antonyan@gmail.com</a>></div><div>wrote:</div><blockquote type="cite"><div><div><br></div><div>To clarify - that behavior is already implemented in merge (more</div><div>specifically merge.data.table). I don't really have a view on having it in</div><div>X[Y] as well - I don't like all.x and all.y as the names, since there are no</div><div>params named 'x' and 'y' in [.data.table (as opposed to merge), but some</div><div>param that would do a full outer join could certainly be added.</div><div><br></div><div><br></div><div>On Fri, May 3, 2013 at 10:09 AM, Gabor Grothendieck</div><div><<a href="mailto:ggrothendieck@gmail.com">ggrothendieck@gmail.com</a>> wrote:</div><blockquote type="cite"><div><div><br></div><div>Yes, sorry.  Its nomatch= which presumably derives from the parameter</div><div>of the same name in the match() function.  If the idea of the nomatch=</div><div>name was to leverage off existing argument names in R then I would</div><div>prefer all.y= to be consistent with merge() in place of nomatch= since</div><div>we are really merging/joining rather than just matching. That would</div><div>also allow extension to all types of join by adding all.an x= argument</div><div>too.</div><div><br></div><div>On Fri, May 3, 2013 at 10:59 AM, Eduard Antonyan</div><div><<a href="mailto:eduard.antonyan@gmail.com">eduard.antonyan@gmail.com</a>> wrote:</div><blockquote type="cite"><div><div>I would prefer nomatch=0 as a default though, simply because that's</div><div>what I</div><div>do most of the time :)</div><div><br></div><div><br></div><div>On Fri, May 3, 2013 at 9:57 AM, Eduard Antonyan</div><div><<a href="mailto:eduard.antonyan@gmail.com">eduard.antonyan@gmail.com</a>></div><div>wrote:</div><blockquote type="cite"><div><div><br></div><div>A correction - the param is called "nomatch", not "match".</div><div><br></div><div>This use case seems like smth a user shouldn't really do - in an ideal</div><div>world you should have them both keyed by the same-name column.</div><div><br></div><div>As is, my view on it is that data.table is correcting the user mistake</div><div>of</div><div>naming the column in Y - y, instead of x, and so the output makes</div><div>sense and</div><div>I don't see the need of complicating the behavior by adding more cases</div><div>one</div><div>has to go through to figure out what the output columns would be.</div><div>Similar to</div><div>asking for X[J(c("b", "c", "d"))] - you wouldn't want an anonymous</div><div>column</div><div>there, would you?</div><div><br></div><div><br></div><div><br></div><div>On Fri, May 3, 2013 at 6:18 AM, Gabor Grothendieck</div><div><<a href="mailto:ggrothendieck@gmail.com">ggrothendieck@gmail.com</a>> wrote:</div><blockquote type="cite"><div><div><br></div><div>I am moving this discussion which started with mdowle to the list.</div><div><br></div><div>Consider this example slightly modified from the data.table FAQ:</div><div><br></div><blockquote type="cite"><div><div>X = data.table(x=c("a","a","b","b","b","c","c"), foo=1:7, key="x")</div><div>Y = data.table(y=c("b","c","d"), bar=c(4,2,3))</div><div>out <- X[Y]; out</div></div></blockquote><div>       x foo bar</div><div>1:     b   3   4</div><div>2:     b   4   4</div><div>3:     b   5   4</div><div>4:     c   6   2</div><div>5:     c   7   2</div><div>6:     d  NA   3</div><div><br></div><div>Note that the first column of the output is labelled x even though</div><div>the</div><div>data to produce it comes from y, e.g. "d" in out$x is not in X$x but</div><div>does appear in Y$y so clearly the data is coming from y as opposed to</div><div>x .  In terms of SQL the above would be written:</div><div><br></div><div>    select Y.y as x, ...</div><div><br></div><div>and the need to renamne the first column of out suggests that there</div><div>may be a deeper problem here.</div><div><br></div><div>Here are some ideas to address this (they would require changes to</div><div>data.table):</div><div><br></div><div>- the default of X[Y,, match=NA] would be changed to a default of</div><div>X[Y,,match=0] so that it corresponds to the defaults in R's merge and</div><div>in SQL joins.</div><div><br></div><div>- the column name of the first column in the example above would be</div><div>changed to y if match=0 but be left at x if match=NA.  In the case</div><div>that match=0 (the proposed new default) x and y are equal so the</div><div>first</div><div>column can be validly labelled as x but in the case that match=NA</div><div>they</div><div>are not so y would be used as the column name.</div><div><br></div><div>- the name match= does seem a bit misleading since R's match only</div><div>matches one item in the target whereas in data.table match matches</div><div>many if mult="all" and that is the default.  Perhaps some thought</div><div>should be given to a name change here?</div><div><br></div><div>The above would seem to correspond more closely to R's merge and SQL</div><div>join defaults.  Any use cases or other comments?</div><div><br></div><div>--</div><div>Statistics & Software Consulting</div><div>GKX Group, GKX Associates Inc.</div><div>tel: 1-877-GKX-GROUP</div><div>email: ggrothendieck at <a href="http://gmail.com">gmail.com</a></div><div>_______________________________________________</div><div>datatable-help mailing list</div><div><a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a></div><div><br></div><div><br></div><div><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a></div></div></blockquote></div></blockquote></div></blockquote><div><br></div><div><br></div><div><br></div><div>--</div><div>Statistics & Software Consulting</div><div>GKX Group, GKX Associates Inc.</div><div>tel: 1-877-GKX-GROUP</div><div>email: ggrothendieck at <a href="http://gmail.com">gmail.com</a></div></div></blockquote></div></blockquote></div></blockquote><div><br></div><div><br></div><div><br></div><div>-- </div><div>Statistics & Software Consulting</div><div>GKX Group, GKX Associates Inc.</div><div>tel: 1-877-GKX-GROUP</div><div>email: ggrothendieck at <a href="http://gmail.com">gmail.com</a></div><div>_______________________________________________</div><div>datatable-help mailing list</div><div><a href="mailto:datatable-help@lists.r-forge.r-project.org">datatable-help@lists.r-forge.r-project.org</a></div><div><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help</a></div></div></div></span>
                 
                 
                 
                 
                </blockquote>
                 
                <div>
                    <br>
                </div>