R Data-Frame: Get Maximum of Variable B condititional on Variable A : <p>I am searching for an efficient and fast way to do the following: 
I have a data frame with, say, 2 variables, A and B, where the values for A can occur several times:</p>

<pre><code>mat&lt;-data.frame('VarA'=rep(seq(1,10),2),'VarB'=rnorm(20))

VarA        VarB
1         0.95848233
2        -0.07477916
3         2.08189370
4         0.46523827
5         0.53500190
6         0.52605101
7        -0.69587974
8        -0.21772252
9         0.29429577
10        3.30514605
1         0.84938361
2         1.13650996
3         1.25143046
</code></pre>

<p>Now I want to get a vector giving me for every unique value of VarA</p>

<pre><code>unique(mat$VarA)
</code></pre>

<p>the maximum of VarB conditional on VarA.
In the example here that would be</p>

<pre><code>1    0.95848233
2    1.13650996
3    2.08189370
etc...
</code></pre>

<p>My data-frame is very big so I want to avoid the use of loops. </p>
