Extracting data from a data frame with conditions
There is a good summary on StackOverflow from the user EDi that I'm referring to. Basically, what you want to do is group the values by year and then select the maximum frequency of each group:

# with dplyr
require(dplyr)
df %&gt;% group_by(year) %&gt;% summarise(freq = max(freq))

# data.table
require(data.table)
dt &lt;- data.table(df)
dt[ , max(freq), by = year]



Check out the linked answer for further possibilities.