<html><head></head><body bgcolor="#FFFFFF"><div>That's really interesting, I can't currently think of another way of doing that as after X[Y] is done the necessary information is lost. </div><div><br></div><div>To retain that functionality and achieve better readability, as in OP, I think smth along the lines of X[Y, head(.SD, i.top), by=.J] would be a good replacement for current syntax.</div>
<div><br></div><div><br>On Apr 24, 2013, at 6:01 PM, Eduard Antonyan <<a href="mailto:eduard.antonyan@gmail.com">eduard.antonyan@gmail.com</a>> wrote:<br><br></div><div></div><blockquote type="cite"><div><div dir="ltr">
that's an interesting example - I didn't realize current behavior would do that, I'm not at a PC anymore but I'll definitely think about it and report back, as it's not immediately obvious to me</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 24, 2013 at 5:50 PM, Matthew Dowle <span dir="ltr"><<a href="mailto:mdowle@mdowle.plus.com" target="_blank">mdowle@mdowle.plus.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div>
<p> </p>
<p>i. prefix is just a robust way to reference join inherited columns:   the 'top' column in the i table.   Like table aliases in SQL.</p>
<p>What about this? :</p>
<pre><div class="im">1> X = data.table(a=1:3,b=1:15, key="a")<br>1> X<br>    a  b<br> 1: 1  1<br> 2: 1  4<br> 3: 1  7<br> 4: 1 10<br> 5: 1 13<br> 6: 2  2<br> 7: 2  5<br> 8: 2  8<br> 9: 2 11<br>10: 2 14<br>

11: 3  3<br>12: 3  6<br>13: 3  9<br>14: 3 12<br>15: 3 15<br></div>1> Y = data.table(a=c(1,2,1), top=c(3,4,2))<div class="im"><br>1> Y<br>   a top<br>1: 1   3<br>2: 2   4<br>3: 1   2<br>1> X[Y, head(.SD,i.top)]<br>

   a  b<br>1: 1  1<br>2: 1  4<br>3: 1  7<br>4: 2  2<br>5: 2  5<br>6: 2  8<br>7: 2 11<br>8: 1  1<br></div>9: 1  4<br>1> </pre><div><div class="h5">
<p> </p>
<p>On <a href="tel:24.04.2013%2023" value="+12404201323" target="_blank">24.04.2013 23</a>:43, Eduard Antonyan wrote:</p>
<blockquote type="cite" style="padding-left:5px;border-left:#1010ff 2px solid;margin-left:5px;width:100%">
<div dir="ltr">I assumed they meant create a table :)
<div>that looks cool, what's i.top ? I can get a very similar to yours result by writing:</div>
<div>X[Y][, head(.SD, top[1]), by = a]</div>
<div>and I probably would want the following to produce your result (this might depend a little on what exactly i.top is):</div>
<div>X[Y, head(.SD, i.top), by = a]</div>
</div>
<div class="gmail_extra"><br><br>
<div class="gmail_quote">On Wed, Apr 24, 2013 at 5:28 PM, Matthew Dowle <span><<a href="mailto:mdowle@mdowle.plus.com" target="_blank">mdowle@mdowle.plus.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span style="text-decoration:underline"></span>
<div>
<p> </p>
<p>That sentence on that linked webpage seems incorect English, since table is a noun not a verb.  Should "table" be "join" perhaps?</p>
<p>Anyway, by-without-by is often used with join inherited scope (JIS).  For example, translating their example :</p>
<pre>1> X = data.table(a=1:3,b=1:15, key="a")<br>1> X<br>    a  b<br> 1: 1  1<br> 2: 1  4<br> 3: 1  7<br> 4: 1 10<br> 5: 1 13<br> 6: 2  2<br> 7: 2  5<br> 8: 2  8<br> 9: 2 11<br>10: 2 14<br>11: 3  3<br>12: 3  6<br>


13: 3  9<br>14: 3 12<br>15: 3 15<br>1> Y = data.table(a=c(1,2), top=c(3,4))<br>1> Y<br>   a top<br>1: 1   3<br>2: 2   4<br>1> X[Y, head(.SD,i.top)]<br>   a  b<br>1: 1  1<br>2: 1  4<br>3: 1  7<br>4: 2  2<br>5: 2  5<br>


6: 2  8<br>7: 2 11<br>1> </pre>
<pre> </pre>
<pre>If there was no by-without-by (analogous to CROSS BY),  then how would that be done?</pre>
<div>
<div>
<pre> </pre>
<p>On <a>24.04.2013 22</a>:22, Eduard Antonyan wrote:</p>
<blockquote style="padding-left:5px;border-left:#1010ff 2px solid;margin-left:5px;width:100%">
<div dir="ltr">By that you mean current behavior? You'd get current behavior by explicitly specifying the appropriate "by" (i.e. "by" equal to the key).
<div>Btw, I'm trying to understand SQL CROSS APPLY vs JOIN using <a href="http://explainextended.com/2009/07/16/inner-join-vs-cross-apply/" target="_blank">http://explainextended.com/2009/07/16/inner-join-vs-cross-apply/</a>, and I can't figure out how by-without-by (or with by-with-by for that matter:) ) helps with e.g. the first example there:</div>


<div>"<span style="font-size:13px;line-height:18px">We table</span><span style="font-size:13px;line-height:18px"> </span><code style="font-size:13px;line-height:18px;padding:0px;margin:0px;font-weight:bold;color:#4488bb">table1</code><span style="font-size:13px;line-height:18px"> </span><span style="font-size:13px;line-height:18px">and</span><span style="font-size:13px;line-height:18px"> </span><code style="font-size:13px;line-height:18px;padding:0px;margin:0px;font-weight:bold;color:#4488bb">table2</code><span style="font-size:13px;line-height:18px">.</span><span style="font-size:13px;line-height:18px"> </span><code style="font-size:13px;line-height:18px;padding:0px;margin:0px;font-weight:bold;color:#4488bb">table1</code><span style="font-size:13px;line-height:18px"> </span><span style="font-size:13px;line-height:18px">has a</span><span style="font-size:13px;line-height:18px"> </span><code style="font-size:13px;line-height:18px;padding:0px;margin:0px;font-weight:bold;color:#4488bb">column</code><span style="font-size:13px;line-height:18px"> </span><span style="font-size:13px;line-height:18px">called</span><span style="font-size:13px;line-height:18px"> </span><code style="font-size:13px;line-height:18px;padding:0px;margin:0px;font-weight:bold;color:#4488bb">rowcount</code><span style="font-size:13px;line-height:18px">.</span></div>


<p style="padding:0px;margin:0px 0px 15px;line-height:18px;font-size:13px">For each row from <code style="padding:0px;margin:0px;font-weight:bold;color:#4488bb">table1</code> we need to select first <code style="padding:0px;margin:0px;font-weight:bold;color:#4488bb">rowcount</code> rows from <code style="padding:0px;margin:0px;font-weight:bold;color:#4488bb">table2</code>, ordered by <code style="padding:0px;margin:0px;font-weight:bold;color:#4488bb"><a href="http://table2.id" target="_blank">table2.id</a>"</code></p>


<p style="padding:0px;margin:0px 0px 15px;line-height:18px;font-size:13px"><code style="padding:0px;margin:0px;font-weight:bold;color:#4488bb"><br></code></p>
</div>
<div class="gmail_extra"><br><br>
<div class="gmail_quote">On Wed, Apr 24, 2013 at 4:01 PM, Matthew Dowle <span><<a href="mailto:mdowle@mdowle.plus.com" target="_blank">mdowle@mdowle.plus.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">But then what would be analogous to CROSS APPLY in SQL?<br>
<div><br> > I'd agree with Eduard, although it's probably too late to change behavior<br> > now.  Maybe for data.table.2?  Eduard's proposal seems more closely<br> > aligned with SQL behavior as well (SELECT/JOIN, then GROUP, but only if<br>

 > requested).<br> ><br> > S.<br> ><br> >> Date: Mon, 22 Apr 2013 08:17:59 -0700</div>
>> From: <a href="mailto:eduard.antonyan@gmail.com" target="_blank">eduard.antonyan@gmail.com</a><br> >> To: <a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">datatable-help@lists.r-forge.r-project.org</a><br>


<div>>> Subject: Re: [datatable-help] changing data.table by-without-by<br> >> syntax       to      require a "by"<br> >><br> >> I think you're missing the point Michael. Just because it's possible to<br>

 >> do it<br> >> the way it's done now, doesn't mean that's the best way, as I've tried<br> >> to<br> >> argue in the OP. I don't think you've addressed the issue of unnecessary<br>

 >> complexity pointed out in OP.<br> >><br> >><br> >><br> >> --<br> >> View this message in context:<br> >> <a href="http://r.789695.n4.nabble.com/changing-data-table-by-without-by-syntax-to-require-a-by-tp4664770p4664990.html" target="_blank">http://r.789695.n4.nabble.com/changing-data-table-by-without-by-syntax-to-require-a-by-tp4664770p4664990.html</a><br>

 >> Sent from the datatable-help mailing list archive at <a href="http://Nabble.com">Nabble.com</a>.<br> >> _______________________________________________<br> >> datatable-help mailing list</div>
>> <a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">datatable-help@lists.r-forge.r-project.org</a><br>
<div>>> <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> >                                         _______________________________________________<br>

 > datatable-help mailing list</div>
> <a href="mailto:datatable-help@lists.r-forge.r-project.org" target="_blank">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>

<br><br></blockquote>
</div>
</div>
</blockquote>
<p> </p>
<div> </div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
<p> </p>
<div> </div>
</div></div></div>
</blockquote></div><br></div>
</div></blockquote></body></html>