<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Consider this set of code:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>DT1<-data.table(A1=1:100,A2=1:100,A3=1:100,B1=101:200,B2=101:200,B3=101:200,C1=301:400,D1=301:400,grp=rep(1:5,each=20))<o:p></o:p></p><p class=MsoNormal>setkey(DT1,grp)<o:p></o:p></p><p class=MsoNormal>(DT2<-DT1[,lapply(.SD,sum),by=grp]) # from data.table FAQ<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I have two questions:<o:p></o:p></p><p class=MsoNormal>1. I have many columns like C1 and D1 that I don't want to include in the new data.table (nor do I want grp.1 in it). How can I nicely have these not be part of my result? (If it helps, I know the indices for the A and the B columns)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>2. However, in addition to (and s
what I want is this result:<o:p></o:p></p><p class=MsoNormal>DT2[,list(sum(A1+A2+A3),sum(B1+B2+B3)),by=grp]<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Now, in the actual data set, it's more like A1 to A30 and B1 to B20, and I will be doing this for many subsets of the A's and B's.<o:p></o:p></p><p class=MsoNormal>So, I would like to have a way to easily find the sum (or sd, or ...) by some easier method than by referencing the column names--use of column indices would be nice for the actual problem. I know that the column numbers can be referenced with with=FALSE, but don’t really see how to use that in this problem.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Any ideas? Thanks.<o:p></o:p></p></div></body></html>