<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: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;}
span.apple-style-span
        {mso-style-name:apple-style-span;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</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=Section1>
<p class=MsoNormal><span class=apple-style-span><span style='font-size:10.0pt;
font-family:"Arial","sans-serif";color:black'>Someone in r-help recommended me
to post the question in this group … TIA<o:p></o:p></span></span></p>
<p class=MsoNormal><span class=apple-style-span><span style='font-size:10.0pt;
font-family:"Arial","sans-serif";color:black'><o:p> </o:p></span></span></p>
<p class=MsoNormal><span class=apple-style-span><span style='font-size:10.0pt;
font-family:"Arial","sans-serif";color:black'>Hello Group,</span></span><span
style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'><br>
<br>
<span class=apple-style-span>I need a modification in the data.table example to
get my intended</span><br>
<span class=apple-style-span>result shown below ... is there a more simple way!</span><br>
<br>
<span class=apple-style-span>dt <- data.table(A = rep(1:3, each=4), B =
rep(1:4, each=3), C = rep(1:2, 6))</span><br>
<span class=apple-style-span>dt[, transform(.SD,D=mean(A)), by="B"]</span><br>
<br>
<br>
<span class=apple-style-span>The result I want is below ... which is probably
long winded!</span><br>
<br>
<span class=apple-style-span>data.table(unique(as.data.frame(dt[,
transform(.SD,D=mean(A)),</span><br>
<span class=apple-style-span>by="B"][,list(B,D)])))</span><br>
<span class=apple-style-span> B D</span><br>
<span class=apple-style-span>[1,] 1 1.000000</span><br>
<span class=apple-style-span>[2,] 2 1.666667</span><br>
<span class=apple-style-span>[3,] 3 2.333333</span><br>
<span class=apple-style-span>[4,] 4 3.000000</span><br>
<br>
<span class=apple-style-span>Thank you.</span></span><o:p></o:p></p>
</div>
</body>
</html>