<font face="arial, helvetica, sans-serif">as.data.table(lapply(DT, sum)) works and doesn't seem much less elegant?</font><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">(Well -- it would work if you were not trying to take the sum of a factor ;-))</font></div>
<div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">t</font><br><div><br><div class="gmail_quote">On Mon, Jan 9, 2012 at 4:45 PM, Joseph Voelkel <span dir="ltr"><<a href="mailto:jgvcqa@rit.edu">jgvcqa@rit.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#222222"># from help(data.table)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#222222">DT = data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#222222">DT[,lapply(.SD,sum),by=x] # this works fine<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#222222"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#222222"># but this fails<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#222222">DT[,lapply(.SD,sum)]<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#222222"># with this message: Error in lapply(.SD, sum) : object '.SD' not found<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#222222"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#222222"># Am I missing something obvious here?<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p></div></div><br>_______________________________________________<br>
datatable-help mailing list<br>
<a href="mailto:datatable-help@lists.r-forge.r-project.org">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></blockquote></div><br></div></div>