Final. Used aggregate rather than tapply.