With your data
df<- structure(list(value = c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L), factorA = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L), .Label = c("a", "b", "c"), class = "factor"), factorB = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 3L), .Label = c("e", "f", "g", "k", "l", "m"), class = "factor")), .Names = c("value", "factorA", "factorB"), class = "data.frame", row.names = c(NA, -8L))
Using the ddply
in plyr
> df2<-ddply(df,c('factorA'),function(x) x[which(x$value==max(x$value)),]) value factorA factorB 1 3 ag 2 3 bm 3 2 cg
Or
> rownames(df2) <- df2$factorA > df2 value factorA factorB a 3 ag b 3 bm c 2 cg