Note that there are some explanatory texts on larger screens.

plurals
  1. POR: When using data.table how do I get columns of y when I do x[y]?
    primarykey
    data
    text
    <p><strong><em>UPDATE</em></strong>: Old question ... it was resolved by data.table v1.5.3 in Feb 2011.</p> <p>I am trying to use the <code>data.table</code> package, and really like the speedups I am getting, but I am stumped by this error when I do <code>x[y, &lt;expr&gt;]</code> where <code>x</code> and <code>y</code> are "data-tables" with the same key, and <code>&lt;expr&gt;</code> contains column names of both <code>x</code> and <code>y</code>:</p> <pre><code>require(data.table) x &lt;- data.table( foo = 1:5, a = 5:1 ) y &lt;- data.table( foo = 1:5, boo = 10:14) setkey(x, foo) setkey(y, foo) &gt; x[y, foo*boo] Error in eval(expr, envir, enclos) : object 'boo' not found </code></pre> <p>UPDATE... To clarify the functionality I am looking for in the above example: I need to do the equivalent of the following:</p> <pre><code>with(merge(x,y), foo*boo) </code></pre> <p>However according to the below extract from the <code>data.table</code> FAQ, this should have worked:</p> <blockquote> <p>Finally, although it appears as though x[y] does not return the columns in y, you can actually use the columns from y in the j expression. This is what we mean by join inherited scope. Why not just return the union of all the columns from x and y and then run expressions on that? It boils down to eciency of code and what is quicker to program. When you write x[y,foo<em>boo], data.table automatically inspects the j expression to see which columns it uses. It will only subset, or group, those columns only. Memory is only created for the columns the j uses. Let's say foo is in x, and boo is in y (along with 20 other columns in y). Isn't x[y,foo</em>boo] quicker to program and quicker to run than a merge step followed by another subset step ?</p> </blockquote> <p>I am aware of <a href="https://stackoverflow.com/questions/2232699/r-how-to-do-a-data-table-merge-operation">this question</a> that addressed a similar issue, but it did not seem to have been resolved satisfactorily. Anyone know what I am missing or misunderstanding? Thanks.</p> <p>UPDATE: I asked on the data-table help mailing list and the package author (Matthew Dowle) <a href="http://r.789695.n4.nabble.com/Cannot-access-cols-of-y-when-doing-x-y-tt3231504.html" rel="nofollow noreferrer">replied</a> that indeed the FAQ quoted above is wrong, so the syntax I am using will not work currently, i.e. I cannot refer to the <code>y</code> columns in the <code>j</code> (i.e. second) argument when I do <code>x[y,...]</code>. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload