<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't it work for you if that is the case?<br></font><div><div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace">DF <- </font><span class="Apple-style-span" style="font-family: 'courier new', monospace; ">data.frame(a=1:200, b=1:10)</span></div>
<meta charset="utf-8"><div><font class="Apple-style-span" face="'courier new', monospace">DT <- as.data.table(DF)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">subDT <- subset(DT, select=a)</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">class(DT)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">subDF <- subset(DF, select=a)</font></div><div>
<font class="Apple-style-span" face="'courier new', monospace">class(DF)</font></div><div><font class="Apple-style-span" face="'courier new', monospace">identical(as.data.frame(DT), DF)</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br>
</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font></div><div><font class="Apple-style-span" face="'courier new', monospace"><br></font><div class="gmail_quote">On Wed, Jul 20, 2011 at 12:50 PM, Chris Neff <span dir="ltr"><<a href="mailto:caneff@gmail.com">caneff@gmail.com</a>></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 "with" doesn't seem to do what I want... but at least it is consistent!<div>
<div></div><div class="h5"><br><br><div class="gmail_quote">2011/7/20 Timothée Carayol <span dir="ltr"><<a href="mailto:timothee.carayol@gmail.com" target="_blank">timothee.carayol@gmail.com</a>></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="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"><br>
</font><div class="gmail_quote">2011/7/20 Timothée Carayol <span dir="ltr"><<a href="mailto:timothee.carayol@gmail.com" target="_blank">timothee.carayol@gmail.com</a>></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's the best solution, though.<br>
</font><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', 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"><<a href="mailto:caneff@gmail.com" target="_blank">caneff@gmail.com</a>></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("x","y")</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't give me back what I want, and DF[,var.names,with=FALSE] returns an error because with doesn'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>