library(sqldf) system.time(t5<-sqldf('SELECT a, avg(b) FROM mydf GROUP BY a'))