[R] aggregate: "sum" not meaningful for factors

Petr Pikal petr.pikal at precheza.cz
Thu Jan 2 16:12:02 CET 2003


On 2 Jan 2003 at 7:58, Sundar Dorai-Raj wrote:

> Tord,
> 
> Tord Snall wrote:
> > Dear all,
> > I try to summarise my data per category using aggregate, but for
> > some reason I get the error message "sum" not meaningful for factors
> > even though my vector is numeric. The data set is shown below.
> > 
> > Could someone please give a hint.
> > 
> > Thanks in advance!
> > 
> > Sincerely,
> > Tord
> > 
> > 
> 
> aggregate requires the first argument to be numeric if you're using
> sum 
>   or mean. The way you had it, aggregate was trying to sum your 
> classification variable as well which is of class `factor'. Try the
> following instead.
> 
> > aggregate(list(tallstubbyta = test$tallstubbyta,
>              list(ObjektID = test$ObjektID), sum)

Or

aggregate(test$tallstubbyta,list(test$ObjectID),sum)




> 
> Regards,
> Sundar


Cheers
Petr Pikal
petr.pikal at precheza.cz
p.pik at volny.cz




More information about the R-help mailing list