title: Sorting and aggregating in R
body: <p>I used the <strong>aggregate function</strong> in R to bring down my data entries from <strong>90k to 1800</strong>. </p>
  
  <pre><code>a=test$ID
  b=test$Date
  c=test$Value
  d=test$Value1
  sumA=aggregate(c, by=list(Date=b,Id=a), FUN=sum)
  sumB=aggregate(d, by=list(Date=b,Id=a), FUN=sum)
  final[1]=sumA[1],final[2]=sumA[2]
  final[3]=sumA[3]/sumB[3]
  </code></pre>
  
  <p>Now I have data in <strong>20 different dates in a month</strong> with close to <strong>90 different ids each day</strong> so its around <strong>1800 entries in the final table</strong> .</p>
  
  <p>My question is that I want to aggregate further down and find the maximum value of final[3] for each date so that I am just left with 20 values .</p>
  
  <p>In simple terms - 
  There are 20 days .
  Each day has 90 values for 90 ids
  I want to find maximum of these 90 values for each day .
  So at last I would be left with just 20 values for 20 days . </p>
  
  <p>Now aggregate function is not working here with function <strong>'max'</strong> instead of sum</p>
  
  <pre><code>Date    ID    Value   Value1 
  1        A      20      10  
  1        A      25      5  
  1        B      50      5  
  1        B      50      5
  1        C      25      25 
  1        C      35      5  
  2        A      30      10  
  2        A      25      45  
  2        B      40      10   
  2        B      40      30  
  </code></pre>
  
  <p>This is the Data </p>
  
  <p>Now By using Aggregate function I got final table as </p>
  
  <pre><code>Date    ID   x
  1       A    45/15=3
  1       B    100/10=10
  1       c    60/30=2
  2       A    55/55=1
  2       B    80/40=2
  </code></pre>
  
  <p>Now I want maximum value for date 1 and 2 thats it </p>
  
  <pre><code>Date   max- Value
  1      10
  2       2
  </code></pre>