<div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">I guess another solution, which I don&#39;t expect to be much more satisfactory, is something like:</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br>

</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">&quot;[.data.frame&quot;(DT, c(&quot;a&quot;, &quot;b&quot;)) (to return the columns &quot;a&quot; and &quot;b&quot;, whether DT is a data.table or a data.frame)</font></div>

<div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace">t</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br>

</font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font></div><div><font class="Apple-style-span" face="&#39;courier new&#39;, monospace"><br></font><div class="gmail_quote">On Wed, Jul 20, 2011 at 1:06 PM, Chris Neff <span dir="ltr">&lt;<a href="mailto:caneff@gmail.com">caneff@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">I&#39;m used to seeing the column names at the bottom of the column too, but that is only if the data.table is long enough. My example was too short for that, so I made the same sort of mistake you did :(<div>

<br></div><div>

Okay, that is a way, but is it a good way? Not sure...<div><div></div><div class="h5"><br><br><div class="gmail_quote">2011/7/20 Timothée Carayol <span dir="ltr">&lt;<a href="mailto:timothee.carayol@gmail.com" target="_blank">timothee.carayol@gmail.com</a>&gt;</span><br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><font face="courier new,monospace">Sorry my mistake -- subset does return a data.table. </font><div><font face="courier new,monospace">(I was using as an example a data.table with 100 rows, and stupidly using the fact that it printed the whole thing rather than the 10 first rows only as my criterion for whether it worked or not.. Omitting that print.data.table does print up to 100 rows. I feel a bit stupid.) </font></div>





<div><font face="courier new,monospace"><br></font></div><div><font face="courier new,monospace">Why doesn&#39;t it work for you if that is the case?<br></font><div><div><div><font face="&#39;courier new&#39;, monospace"><br>





</font></div><div><font face="&#39;courier new&#39;, monospace">DF &lt;- </font><span style="font-family:&#39;courier new&#39;, monospace">data.frame(a=1:200, b=1:10)</span></div>

<div><font face="&#39;courier new&#39;, monospace">DT &lt;- as.data.table(DF)</font></div><div><font face="&#39;courier new&#39;, monospace">subDT &lt;- subset(DT, select=a)</font></div>

<div><font face="&#39;courier new&#39;, monospace">class(DT)</font></div><div><font face="&#39;courier new&#39;, monospace">subDF &lt;- subset(DF, select=a)</font></div><div>

<font face="&#39;courier new&#39;, monospace">class(DF)</font></div><div><font face="&#39;courier new&#39;, monospace">identical(as.data.frame(DT), DF)</font></div><div><div></div><div><div><font face="&#39;courier new&#39;, monospace"><br>





</font></div><div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace"><br></font><div class="gmail_quote">On Wed, Jul 20, 2011 at 12:50 PM, Chris Neff <span dir="ltr">&lt;<a href="mailto:caneff@gmail.com" target="_blank">caneff@gmail.com</a>&gt;</span> wrote:<br>





<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yeah I realized that myself. <div><br></div><div>Another one: the function &quot;with&quot; doesn&#39;t seem to do what I want... but at least it is consistent!<div>





<div></div><div><br><br><div class="gmail_quote">2011/7/20 Timothée Carayol <span dir="ltr">&lt;<a href="mailto:timothee.carayol@gmail.com" target="_blank">timothee.carayol@gmail.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><font face="courier new,monospace">Sorry -- </font><div><font face="courier new,monospace"><br></font></div><div><font face="courier new,monospace">subset() was a poor idea, as it will return a data.frame even if the argument is a data.table..<br>









</font></div><div><div></div><div><div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace"><br>









</font><div class="gmail_quote">2011/7/20 Timothée Carayol <span dir="ltr">&lt;<a href="mailto:timothee.carayol@gmail.com" target="_blank">timothee.carayol@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">









<font face="courier new,monospace"><div><font face="courier new,monospace">Hi--</font></div><div><font face="courier new,monospace"><br></font></div></font><font face="courier new,monospace">You can use the subset() command with the select= option; not sure it&#39;s the best solution, though.<br>










</font><div><font face="&#39;courier new&#39;, monospace"><br></font></div><div><font face="&#39;courier new&#39;, monospace">Timothee<br></font></div><div><div class="gmail_quote">
<br></div><div class="gmail_quote"><br></div><div class="gmail_quote"><div><div></div><div>On Wed, Jul 20, 2011 at 12:26 PM, Chris Neff <span dir="ltr">&lt;<a href="mailto:caneff@gmail.com" target="_blank">caneff@gmail.com</a>&gt;</span> wrote:<br>









</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div>
I have a function where I pass a data frame and some variable names to calculate statistics on. However, I am at a loss as to how to write it correctly so that both data.frame and data.table work with it. If I have:<div>









<br>


</div><div>DF = data.frame(x=1:10,y=2:11,z=3:12)</div><div><br></div><div>DT = data.table(DF)</div><div><br></div><div>var.names = c(&quot;x&quot;,&quot;y&quot;)</div><div><br></div><div><br></div><div>I can do the following things to subset:</div>












<div><br></div><div>DT[,var.names,with=FALSE]</div><div>DF[,var.names]</div><div><br></div><div><br></div><div>but of course DT[,var.names] won&#39;t give me back what I want, and DF[,var.names,with=FALSE] returns an error because with doesn&#39;t exist there. So how do I do this?</div>












<div><br></div><div>Thanks,</div><div>-Chris</div><font color="#888888"><div><br></div><div><br></div>
</font><br></div></div>_______________________________________________<br>
datatable-help mailing list<br>
<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></blockquote></div><br></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div>
</blockquote></div><br></div></div></div></div></div></div>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div></div>