数据量小可以用aggregate,如果数据量很大,tapply 和 by 的运行速度比aggregate快一个数量级,此时用tapply 更胜一筹,用$太麻烦,可以用attach函数,但是用完要记得用detach解绑。