How to find average of a col1 grouping by col2 <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="http://stackoverflow.com/questions/10748253/idiomatic-r-code-for-partitioning-a-vector-by-an-index-and-performing-an-operati">Idiomatic R code for partitioning a vector by an index and performing an operation on that partition</a><br> <a href="http://stackoverflow.com/questions/12185319/how-to-calculate-median-of-profits-for-a-particular-country">How to calculate median of profits for a particular country</a> </p> </blockquote> <p>I am trying to find average of a column by using another column in R.It's so easy to do it in SQL but not able to find proper functions and implement them.Here is some sample data as below.</p> <pre><code>data("Forbes2000", package = "HSAUR") head(Forbes2000) ## rank name country category sales profits assets marketvalue ## 1 1 Citigroup United States Banking 94.71 17.85 1264.03 255.30 ## 2 2 General Electric United States Conglomerates 134.19 15.59 626.93 328.54 ## 3 3 American Intl Group United States Insurance 76.66 6.46 647.66 194.87 ## 4 4 ExxonMobil United States Oil &amp; gas operations 222.88 20.96 166.99 277.02 ## 5 5 BP United Kingdom Oil &amp; gas operations 232.57 10.27 177.57 173.54 ## 6 6 Bank of America United States Banking 49.01 10.81 736.45 117.55 </code></pre>