title: Aggregate Function in R within FOR loop
body: <p>I have a data table (temp3) which is like (original table has around 1 million rows) -</p>
  
  <pre><code>creative_code   reqcount    hasbought   numclick    FeedbackCPM bidvalue_CPMf   browser
  79  5   1   0   19   9  C
  1   0   0   0   39  50  C
  79  3   1   0 1205 684  C
  1   7   1   5   82 159  C
  1   9   0   3   15  77  C
  79  5   0   0 1575  700 C
  1   0   0   0   95  300 C
  1   4   1   4   95  300 C
  1   3   0   0   1   300 C
  1   8   0   0  30   65  C
  1   9   1   0   17  293 C
  1   4   0   1  140  300 IE
  79  4   0     0 838 271 F
  79  7   1     2 0   13  C
   1  9   2   0    67 160 C
  79  2   0   0   268 176 F
  79  0   1   23 1634 700 C
  79  1   0   0     0 300 C
  79  5   0   0   143  87 C
  79  7   2   0     0   9 IE
   1  3   0   0   178 300 IE
   1  7   0   0   111 200  F
  </code></pre>
  
  <p>What I require is mean for all Creative_code with reqcount, hasbought,hasclick separately. I am able to find mean for Creative_code+reqcount separately by using the command -
      aggregate(bidvalue_CPMf~creative_code+reqcount,data=temp3,FUN=mean)</p>
  
  <p>However, if I use the following code, I get an error - </p>
  
  <pre><code>Code - 
   for (j in names(temp3))        aggregate(bidvalue_CPMf~creative_code+j,data=temp3,FUN=mean)
  Error - Error in model.frame.default(formula = bidvalue_CPMf ~ creative_code +  :   variable lengths differ (found for 'j')
  </code></pre>
  
  <p>Please help.</p>