library(reshape2) meltdf=melt(mydf) system.time(t3<-dcast(meltdf,a~variable,mean))