I have a data.frame with two columns: year and score. The years go from 2000-2012 and each year can be listed multiple times. In the s
data.frame
year
score
data <- data.frame(year = c(2000, 2001, 2000), score = c(18, 22, 21)) new.year <- unique(data$year) new.score <- sapply(new.year, function(y) max(data[data$year == y, ]$score)) data <- data.frame(year = new.year, score = new.score)