apply() functions

library(ggplot2)
tapply(diamonds$price, diamonds$cut, mean)
##      Fair      Good Very Good   Premium     Ideal 
##  4358.758  3928.864  3981.760  4584.258  3457.542

You get a named vector!