如何在一个代码中写下聚合代码,以便输出看起来像年,1岁,2岁,3岁,4岁,5岁。
aggregate(sample$age==1~ sample$year, sample, sum)
aggregate(sample$age==2~ sample$year, sample, sum)
aggregate(sample$age==3~ sample$year, sample, sum)
aggregate(sample$age==4~ sample$year, sample, sum)
aggregate(sample$age==5~ sample$year, sample, sum)