# apply() mat <- matrix(1:200,nrow=10) rownames(mat) <- letters[1:10] colnames(mat) <- 1:20 mat ans <- apply(mat,MARGIN=1,mean) ans ans2 <- apply(mat,MARGIN=2,mean) ans2 # by() data(iris) head(iris) attach(iris) by(iris[,1:4],Species,colMeans) # tapply( ) (works better for one variable at a time, by( ) is more efficient for more than one numeric variable at a time) tapply(Sepal.Length,Species,mean) # aggregate() aggregate(Sepal.Length~Species,data=iris,mean) aggregate(.~Species,data=iris,mean)