<div dir="ltr"><div class="gmail_default" style="font-family:'trebuchet ms',sans-serif;font-size:small;color:rgb(51,51,51)">Caros,</div><div class="gmail_default" style="font-family:'trebuchet ms',sans-serif;font-size:small;color:rgb(51,51,51)">
<br></div><div class="gmail_default" style="font-family:'trebuchet ms',sans-serif;font-size:small;color:rgb(51,51,51)">rotineiramente me deparo com um problema que não sei como resolver. Considerem o seguinte exemplo:</div>
<div class="gmail_default" style="font-family:'trebuchet ms',sans-serif;font-size:small;color:rgb(51,51,51)"><br></div><div class="gmail_default" style><div class="gmail_default" style><span style="color:rgb(51,51,51);font-family:'trebuchet ms',sans-serif">(c1 <- trunc(runif(1000,1,10)))</span><br>
</div><div class="gmail_default" style><font color="#333333" face="trebuchet ms, sans-serif">(c2 <- trunc(runif(1000,5,70)))</font></div><div class="gmail_default" style><font color="#333333" face="trebuchet ms, sans-serif">(c3 <- trunc(runif(1000,1,4)))</font></div>
<div class="gmail_default" style><font color="#333333" face="trebuchet ms, sans-serif">(var <- rnorm(1000,10,2))</font></div><div class="gmail_default" style><font color="#333333" face="trebuchet ms, sans-serif">(peso <- round(rnorm(1000,1,.2)^2,1))</font></div>
<div class="gmail_default" style><font color="#333333" face="trebuchet ms, sans-serif">df <- data.frame(c1,c2,c3,var,peso)</font></div><div class="gmail_default" style><font color="#333333" face="trebuchet ms, sans-serif"><br>
</font></div><div class="gmail_default" style><font color="#333333" face="trebuchet ms, sans-serif"><br></font></div><div class="gmail_default" style><font color="#333333" face="trebuchet ms, sans-serif">Gostaria de uma função que pudesse me fornecer em uma única tabela do tipo</font></div>
<div class="gmail_default" style><font color="#333333" face="trebuchet ms, sans-serif">cols = c1,c2,c3,count,medvar</font></div><div class="gmail_default" style><font color="#333333" face="trebuchet ms, sans-serif">e, mais genericamente,</font></div>
<div class="gmail_default" style><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif">cols = c1,c2,c3,somapeso,medpondvar</font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif"><br>
</font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif">com todas as combinações existentes (as vezes todas as teoricamente possiveis) entre c1,c2,c3</font></div><div class="gmail_default">
<font color="#333333" face="trebuchet ms, sans-serif">c1</font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif">c2</font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif">c3</font></div>
<div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif">c1*c2</font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif">c1*c3</font></div><div class="gmail_default">
<font color="#333333" face="trebuchet ms, sans-serif">c2*c3</font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif">c1*c2*c3</font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif"><br>
</font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif">De forma mais específica, gostaria:</font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif"><div class="gmail_default">
<br></div><div class="gmail_default">t1 <- aggregate(list(count = df$var), list(c1=rep('*tot',1000) ,c2=rep('*tot',1000),c3=rep('*tot',1000)),length)</div><div class="gmail_default">tc1 <- aggregate(list(count = df$var), list(c1=df$c1 ,c2=rep('*tot',1000),c3=rep('*tot',1000)),length)</div>
<div class="gmail_default">tc2 <- aggregate(list(count = df$var), list(c1=rep('*tot',1000),c2=df$c2 ,c3=rep('*tot',1000)),length)</div><div class="gmail_default">tc3 <- aggregate(list(count = df$var), list(c1=rep('*tot',1000),c2=rep('*tot',1000),c3=df$c3 ),length)</div>
<div class="gmail_default">tc1c2 <- aggregate(list(count = df$var), list(c1=df$c1 ,c2=df$c2 ,c3=rep('*tot',1000)),length)</div><div class="gmail_default">tc1c3 <- aggregate(list(count = df$var), list(c1=df$c1 ,c2=rep('*tot',1000),c3=df$c3 ),length)</div>
<div class="gmail_default">tc2c3 <- aggregate(list(count = df$var), list(c1=rep('*tot',1000),c2=df$c2 ,c3=df$c3 ),length)</div><div class="gmail_default">tc1c2c3 <- aggregate(list(count = df$var), list(c1=df$c1 ,c2=df$c2 ,c3=df$c3),length)</div>
<div class="gmail_default">comp1 <- rbind(t1,tc1,tc2,tc3,tc1c2,tc1c3,tc2c3,tc1c2c3)</div><div class="gmail_default">rm(t1,tc1,tc2,tc3,tc1c2,tc1c3,tc2c3,tc1c2c3)</div><div class="gmail_default"><br></div><div class="gmail_default">
t1 <- aggregate(list(medvar = df$var), list(c1=rep('*tot',1000) ,c2=rep('*tot',1000),c3=rep('*tot',1000)),mean)</div><div class="gmail_default">tc1 <- aggregate(list(medvar = df$var), list(c1=df$c1 ,c2=rep('*tot',1000),c3=rep('*tot',1000)),mean)</div>
<div class="gmail_default">tc2 <- aggregate(list(medvar = df$var), list(c1=rep('*tot',1000),c2=df$c2 ,c3=rep('*tot',1000)),mean)</div><div class="gmail_default">tc3 <- aggregate(list(medvar = df$var), list(c1=rep('*tot',1000),c2=rep('*tot',1000),c3=df$c3 ),mean)</div>
<div class="gmail_default">tc1c2 <- aggregate(list(medvar = df$var), list(c1=df$c1 ,c2=df$c2 ,c3=rep('*tot',1000)),mean)</div><div class="gmail_default">tc1c3 <- aggregate(list(medvar = df$var), list(c1=df$c1 ,c2=rep('*tot',1000),c3=df$c3 ),mean)</div>
<div class="gmail_default">tc2c3 <- aggregate(list(medvar = df$var), list(c1=rep('*tot',1000),c2=df$c2 ,c3=df$c3 ),mean)</div><div class="gmail_default">tc1c2c3 <- aggregate(list(medvar = df$var), list(c1=df$c1 ,c2=df$c2 ,c3=df$c3),mean)</div>
<div class="gmail_default">comp2 <- rbind(t1,tc1,tc2,tc3,tc1c2,tc1c3,tc2c3,tc1c2c3)</div><div class="gmail_default">rm(tc1,tc2,tc3,tc1c2,tc1c3,tc2c3,tc1c2c3)</div><div class="gmail_default"><br></div><div class="gmail_default">
comp <- merge(comp1,comp2,by=c('c1','c2','c3'),all=T)</div><div class="gmail_default">rm(comp1,comp2)</div><div><br></div></font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif"><br>
</font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif">Exite algum pacote que faca isso?</font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif"><br>
</font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif"><br></font></div><div class="gmail_default"><font color="#333333" face="trebuchet ms, sans-serif"><br></font></div><div class="gmail_default">
<font color="#333333" face="trebuchet ms, sans-serif"><br></font></div><div><font color="#333333" face="trebuchet ms, sans-serif"><br></font></div></div></div></div>