Reverted to plyr instead of ddply (which requires R>3.0.2).