R - Display row with biggest value in a new dataframe : <p>I have a dataframe like this one:  </p>

<pre><code>x1= c("Station1", "Station2", "Station3", "Station4", "Station5", "Station6", "Station7", "Station8", "Station9", "Station10")
x2= seq(-2,10 , length=10)
x3= seq(30, 45, length=10)
x4= c(1, 3, 2, 1, 4, 2, 4, 3, 3, 1)
x5= seq(10, 100, length=10)
df = data.frame(Station=x1, Lon=x2, Lat=x3, Number=x4, Size=x5)

&gt;df
    Station        Lon      Lat Number Size
1   Station1 -2.0000000 30.00000      1   10
2   Station2 -0.6666667 31.66667      3   20
3   Station3  0.6666667 33.33333      2   30
4   Station4  2.0000000 35.00000      1   40
5   Station5  3.3333333 36.66667      4   50
6   Station6  4.6666667 38.33333      2   60
7   Station7  6.0000000 40.00000      4   70
8   Station8  7.3333333 41.66667      3   80
9   Station9  8.6666667 43.33333      3   90
10 Station10 10.0000000 45.00000      1  100
</code></pre>

<p>The Stations are in 4 different groups, that can be seen in the $Number column. Now I want to extract the Stations with the biggest value in the df$Size column for each group. So I want to have a new dataframe with 4 rows (one for each group) and the same columns.</p>

<p>It should look like this:</p>

<pre><code>    Station        Lon      Lat Number Size
6   Station6  4.6666667 38.33333      2   60
7   Station7  6.0000000 40.00000      4   70
9   Station9  8.6666667 43.33333      3   90
10 Station10 10.0000000 45.00000      1  100
</code></pre>

<p>I already tried it like that to get the row number, but it doesnt work. </p>

<pre><code>index1 = df$Number=="1" 
index2 = df$Number=="2" 
index3 = df$Number=="3" 
index4 = df$Number=="4" 

df[index1][which.max(df$Size),]
</code></pre>

<p>Any ideas?</p>
